0

有时在一个分支工作你最终会得到比你计划的更多的东西,并意识到将你所做的一些事情拆分到另一个分支是值得的。

例如,在修复妨碍您的错误、添加文档或进行一些您在途中注意到的小功能修复时。

将您所做的一些工作拆分到新分支中的最简单方法是什么?

4

2 回答 2

0

用于checkout -i以交互方式将您想要的位选择到新分支中,提交该位,然后git revert在大分支上使用以删除您拆分的内容。

例如

---A         - @{upstream}
    \
     \--B--C - LargeBranch

在 LargeBranch 所基于的同一个上游分支上创建一个新分支SplitBranch,并以交互方式选择您想要的更改:

git checkout -b SplitBranch @{upstream}
git checkout -i LargeBranch
git commit

导致:

---A         - @{upstream}
   |\
   | \--B--C - LargeBranch
    \
     \--D    - SplitBranch

然后,使用以下命令轻松删除已拆分SplitBranch的内容git revert

git checkout LargeBranch
git revert halfFoo

---A            - @{upstream}
   |\
   | \--B--C--E - LargeBranch,  E is inverse of D.
    \
     \--D       - SplitBranch

现在,LargeBranch您移入的内容不再存在SplitBranch

于 2013-03-09T01:05:27.293 回答
0

I'd create a new branch to receive the "too much" changes at some convenient point before the mess, git cherry-pick the commits from the original to it, and then git rebase -i them out of the original. You might split some of the commits before the cherry picking.

To make sure nothing gets lost, start with a git branch save at the HEAD, that way you can mess around with the existing branches; blow all away and start over.

于 2013-03-09T01:13:37.920 回答