相当于Mercurial阶段的Git?

时间:2015-07-31 16:46:41

标签: git version-control mercurial version-control-migration mercurial-phases

在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中执行此操作?

2 个答案:

答案 0 :(得分: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.

我个人更喜欢分支方法,因为它更清洁。

答案 1 :(得分:0)

  

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

我从不使用“git push”的默认行为。要强制执行此操作,可以将push.default设置为“nothing”。然后有两种推动方式:

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

    中有这个
    [remote "origin"]
    ...
     push = refs/heads/export/*:refs/heads/*
    
  2. 因此,如果我确定某些提交已经准备好推送,那么我将分支“export/<feature>”。在我这样做之前,提交不会被“git push”推送。

    1. 或者只是始终明确指定要在命令行中推送的分支。像这样:

      $git push origin 3f42873:refs/heads/12345_foo
      
    2. 这就是我在工作中所做的事情,分支机构总是来去匆匆,我不想跟踪它们。但是它留下了一些错误的机会,所以如果你想确保使用第一个选项。

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