Git rebase 交互式最后 n 次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41464752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git rebase interactive the last n commits
提问by Thomas S.
I have made a bunch of unpushed commits in my feature branch and now want to reorder and partly squash belonging commits visually. I reckon the solution somehow lies in the Git interactive, but how to invoke it?
我在我的功能分支中做了一堆未推送的提交,现在想重新排序并部分压缩属于视觉的提交。我认为解决方案在某种程度上在于 Git 交互,但如何调用它?
$ git rebase --interactive --onto <the-ID-of-the-first-commit-to-rewrite>
just pops up the VI with a
只是用一个弹出VI
noop
content followed by commented information. After exiting, my head is reset to the specified commit.
内容后跟评论信息。退出后,我的头被重置为指定的提交。
How to correctly trigger the interactive rebase for modifying the commits since a certain commit?
如何正确触发交互式变基以修改自某个提交以来的提交?
回答by Chris Maes
you should use
你应该使用
git rebase --interactive <sha1>
where <sha1>
should notbe the sha of the first commit you want to rewrite, but the sha of the commit just before.
这里<sha1>
应该不会是你想重写第一次提交的SHA,但对沙之前提交。
if your history looks like this:
如果你的历史是这样的:
pick 43576ef last commit
...
pick 5116d42 first commit to rewrite
pick cb85072 last good commit
then you can there are different ways to indicate the commit on which to rebase:
那么你可以有不同的方法来指示要重新定位的提交:
git rebase -i cb85072
git rebase -i 5116d42^
where
在哪里
^
means the commit just before.-i
is just short for--interactive
^
表示之前的提交。-i
只是简称--interactive
回答by Oleksandr Kobylianskyi
You can also step back from your last commit by some number of commits. For example, if you want to rebase last 5 commits you can use this command:
git rebase -i HEAD~5
.
您还可以通过一定数量的提交从上次提交后退。例如,如果你想变基过去5个提交你可以使用这个命令:
git rebase -i HEAD~5
。
回答by Golfer
To review and rewrite the last n
commits, use:
要查看和重写最后一次n
提交,请使用:
git rebase -i HEAD~n
p, pick = use commit
p, 选择 = 使用提交
f, fixup = like "squash", but discard this commit's log message
f, fixup = like "squash", 但丢弃这个提交的日志信息
https://www.freecodecamp.org/forum/t/how-to-squash-multiple-commits-into-one-with-git-squash/13231
https://www.freecodecamp.org/forum/t/how-to-squash-multiple-commits-into-one-with-git-squash/13231
回答by bereket gebredingle
The accepted answer is right
接受的答案是正确的
Though, counting n commits to squash and picking the commit id for rebase is tricky
尽管如此,计算 n 次提交压缩并为 rebase 选择提交 id 是很棘手的
git rebase -i HEAD~[N] // N is the number of commits, starting from the most recent one
git rebase -i HEAD~[7]
git rebase -i HEAD~[7]
But if u have tons of commit to squash
但如果你有大量的承诺去壁球
git rebase -i [commit-id] // [commit-id] is the hash of the commit just before the first one
git rebase -i 6394dc
git rebase -i 6394dc
回答by Bustikiller
I miss the action rebase
in your instruction:
我想念rebase
您指令中的操作:
git rebase -i <id-of-commit>
回答by Martin Flaska
If you want to interactively rebase branch B onto branch A using its last N commits, you can generally do this:
如果您想使用最后 N 次提交以交互方式将分支 B 变基到分支 A 上,您通常可以这样做:
git rebase -i --onto A B~N B
git rebase -i --onto A B~N B
e.g.
例如
git rebase -i --onto master feature~3 feature
git rebase -i --onto master feature~3 feature
Works well also non-interactively - without -i
.
非交互式也能很好地工作 - 没有-i
.