如何将最近(但不是最新)提交移动到新分支

[英]How do I move recent (but not latest) commits to a new branch


i.e. how do I go from

即我该如何离开


master : A-B-C-D-E-F-G

to

master: A-B-E-F-G
           \
feature:    C-D 

Obviously its now clear that CD should have been in a feature branch, as that change is now delayed.

显然,现在很清楚CD应该在功能分支中,因为这种变化现在已经延迟了。

This is a subtly different issue to the others I've seen here and and here

对于我在这里和这里看到的其他人来说,这是一个微妙的不同问题

2 个解决方案

#1


2  

This answer assumes you either haven't pushed master or you're the only person working on the project (in which case it doesn't really matter). If you have pushed master and someone else pulled your changes, you'll need to communicate with them to make sure they update their repositories appropriately.

这个答案假设你要么没有推动大师,要么你是唯一一个从事该项目的人(在这种情况下,这并不重要)。如果您已推送主人并且其他人撤消了您的更改,则您需要与他们通信以确保他们适当地更新其存储库。

                                  # Assuming you're on master
git branch <feature> <D>          # Create a branch named <feature> at commit <D>
git rebase --onto <B> <D> master  # Transplant branch

Git rebase documentation has a pretty good graphical explanation of what rebase --onto does.

Git rebase文档对rebase --onto的作用有一个非常好的图解说明。


If you want to avoid a rebase altogether, you should be able to do

如果你想完全避免变革,你应该能够做到

git branch <feature> <D>          # Create a branch named <feature> at commit <D>
git revert <D>                    # undo D
git revert <C>                    # undo C

This will result in a history like this

这将产生这样的历史

A-B-C-D-E-F-G-!D-!C
      ^           ^
   feature      master

Anyone who checks out master, will see code as if commits C and D never happened, you'll just have a couple of reverts in your history. That's the preferred way of backing changes out of a branch that has been pushed.

检查主人的任何人都会看到代码,好像提交C和D从未发生过,你只需要在你的历史中有几个恢复。这是支持已推送的分支更改的首选方法。

#2


3  

Starting at the HEAD (G) of master:

从主人的HEAD(G)开始:

git branch feature D  # Create new branch at D.
git rebase -i B       # Use interactive rebase to remove C D from master.
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/10/25/f9b9f9565b149db5622ba7dc3bb30483.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告