我怎样才能分裂一个埋在历史中的Git提交? [英] How can I split up a Git commit buried in history?
问题描述
我想分割在我推出之前先完成这个提交,但是我看到的大多数指南都与拆分最近的提交或未提交的本地更改有关。
div>
有一个指导可以在rebase手册页中分裂提交 。简要总结如下: 执行包括目标提交(例如 当rebase达到该提交时,使用
git rebase -i < / p>
git reset HEAD ^
在提交之前重置,但保持工作树完好。 add -p
可以用于添加给定文件中的一些更改。如果您想重新使用该功能,请使用 commit -c ORIG_HEAD
原始提交信息。 隐藏你没有提交的部分(或者甚至在提交之前隐藏 stash --keep-index
),测试,然后 git stash pop
将其余部分返回到工作树。继续进行提交,直到你完成所有修改,即有一个干净的工作树。 运行 git rebase --continue
继续在现在分割的提交之后应用提交。
I flubbed up my history and want to do some changes to it. Problem is, I have a commit with two unrelated changes, and this commit is surrounded by some other changes in my local (non-pushed) history.
I want to split up this commit before I push it out, but most of the guides I'm seeing have to do with splitting up your most recent commit, or uncommitted local changes. Is it feasible to do this to a commit that is buried in history a bit, without having to "re-do" my commits since then?
There is a guide to splitting commits in the rebase manpage. The quick summary is:
Perform an interactive rebase including the target commit (e.g.
git rebase -i <commit-to-split>^ branch
) and mark it to be edited.When the rebase reaches that commit, use
git reset HEAD^
to reset to before the commit, but keep your work tree intact.Incrementally add changes and commit them, making as many commits as desired.
add -p
can be useful to add only some of the changes in a given file. Usecommit -c ORIG_HEAD
if you want to re-use the original commit message for a certain commit.If you want to test what you're committing (good idea!) use
git stash
to hide away the part you haven't committed (orstash --keep-index
before you even commit it), test, thengit stash pop
to return the rest to the work tree. Keep making commits until you get all modifications committed, i.e. have a clean work tree.Run
git rebase --continue
to proceed applying the commits after the now-split commit.
这篇关于我怎样才能分裂一个埋在历史中的Git提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!