4

在 mercurial 中,我经常使用秘密变更集来跟踪我在尚未准备好推送的内容上的工作。然后,如果我需要对某个文件进行紧急更改,我可以更新到公共修订,进行更改并推送它,而不必担心我未完成的更改集被推送。

IE:

hg commit -sm "Partial work"
# Crap, prod is down
hg up -r <public version number>
hg commit -m "Fixin prod"
hg out
  1 outgoing change, "Fixin prod"
hg push
hg rebase -r <secret revisions> -d.
# later
hg commit --amend -m "Finished work"
hg phase -dr.
hg out
  1 outgoing change, "Finished work"
hg push 

您将如何在 git 中执行此操作?

4

2 回答 2

2

使用分支:

$ git checkout -b dev #create a new branch based on the current commit in master
# .... work ....
$ git commit -a -m 'super awesome new feature'
# oh noes, production crapped itself!
$ git checkout master
# ... fix ...
$ git commit -a -m 'fixed bug #666'
$ git push master
$ git checkout dev #since we created the branch with -b the first time, we're good now.
$ git merge master # update our dev branch with the changes in master
# ... work on new features ...
# all done and commited and tested
$ git checkout master
$ git merge dev && git branch -d dev # delete the dev branch
$ git push && profit

或者干脆使用git stash

# ... work on new feature ...
# oh noes, production caught a killer virus from aliens
$ git stash
# ... fix and commit and push ...
$ git stash apply # reapply your stashed code
# resume hacking on your new feature.

我个人更喜欢分支方法,因为它更干净。

于 2015-08-01T00:54:08.120 回答
0

您将如何在 git 中执行此操作?

我从不使用“ git push”的默认行为。为了强制执行它,可以设置push.default为“ nothing”。那么推送的方式有2种:

  1. 设置remote.<name>.push。对于我的 github 东西,我通常在我的.git/config

    [remote "origin"]
    ...
     push = refs/heads/export/*:refs/heads/*
    

因此,如果我决定某些提交已准备好推送,我会在那里放置分支“ export/<feature>”。在我这样做之前,提交不会被“ git push”推送。

  1. 或者总是在命令行中明确指定您要推送到哪个分支。像这样:

    $git push origin 3f42873:refs/heads/12345_foo
    

这就是我在工作中所做的事情,分支总是来来去去,我不想跟踪它们中的每一个。但是,它留下了一些出错的机会,所以如果你想确保使用第一个选项。

此处描述了 refspec 语法:https ://www.kernel.org/pub/software/scm/git/docs/git-push.html

于 2015-08-01T19:20:10.550 回答