git rebase --continue 和 --stepback?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5856521/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:23:55  来源:igfitidea点击:

git rebase --continue and --stepback?

git

提问by elmarco

Is there a way to step back a commit during an interactive rebase?

有没有办法在交互式变基期间退回提交?

采纳答案by Moberg

Yes there is. How to step back during an interactive rebase:

就在这里。如何在交互式 rebase 期间后退:

  1. Get the commit hash of your current HEAD, for example with git rev-parse HEAD
  2. run git rebase --edit-todo
  3. insert a pick with that hash to the top of that file pick <hash from step 1>
  4. run git reset --hard HEAD^
  1. 获取当前 HEAD 的提交哈希,例如 git rev-parse HEAD
  2. git rebase --edit-todo
  3. 在该文件的顶部插入一个带有该散列的选择 pick <hash from step 1>
  4. git reset --hard HEAD^

Now you are still in the rebase but one commit back and you are free to continue rebasing with

现在你仍然在变基中,但是一次提交,你可以自由地继续变基

  1. git rebase --continue.
  1. git rebase --continue.

If you don't want the undone commit to be picked straight up without edits you can add edit <HASH>instead of pick <HASH>to the todo list (step 3).

如果您不希望在没有编辑的情况下直接选择撤消的提交,您可以添加edit <HASH>而不是添加pick <HASH>到待办事项列表(第 3 步)。

Addendum: You can remember more hashes, reset to an even earlier point and add multiple picks to redo more than one commit.

附录:您可以记住更多哈希值,重置为更早的点并添加多个选择以重做多次提交。

Explained more clearly here: http://arigrant.com/blog/2014/5/4/git-rebase-stepping-forward-and-back

这里解释得更清楚:http: //arigrant.com/blog/2014/5/4/git-rebase-stepping-forward-and-back

回答by sehe

Nope, as Magnus said.

不,正如马格努斯所说。

However,

然而,

  • git-rerere could come close to what you want in a way: if there were previous manual conflict resolutions that you didn't want to loose, you can enable rerere(prerecorded conflict resolutions) so that they will automatically be resolved in the same way on subsequent merges. Note that this means that you'll have to remember what part you want to resolve differently next time (presumably the goal of having a step-back in the first place?) because - well, rerere assumes you want to applies the same resolution again.
  • git-rerere 可以在某种程度上接近您想要的:如果您不想松散以前的手动冲突解决方案,您可以启用rerere(预先记录的冲突解决方案),以便它们将以相同的方式自动解决后续合并。请注意,这意味着您必须记住下次要以不同的方式解决哪个部分(大概是首先退后一步的目标?)因为 - 好吧,rerere 假设您想再次应用相同的解决方案.

If you look at the implementation of rebase, you might be able to figure out alternative settings for GIT_WORK_TREE/GIT_DIR/GIT_INDEX; You could then perhaps use plumbing commands with a reflog for the rebase-in-progress branch?

如果您查看 rebase 的实现,您可能会找出 GIT_WORK_TREE/GIT_DIR/GIT_INDEX 的替代设置;然后,您可以将管道命令与 reflog 一起用于 rebase-in-progress branch

  • this takes you deep into undocumented internals (beyond the plumbing)
  • you might just as well propose a patch to rebase that implements --step-back
  • 这将带您深入了解未记录的内部结构(超越管道)
  • 你不妨提出一个补丁来实现 --step-back

回答by ralphtheninja

No. You can --continue to continue rebasing (e.g. after you have solved some conflict), --abort (undo and whole rebase process) or --skip to skip current patch.

不可以。您可以--continue 继续rebase(例如,在您解决了一些冲突之后),--abort(撤消和整个rebase 过程)或--skip 以跳过当前补丁。

回答by junvar

Actually u can even if you're not doing interactive rebase.

实际上,即使您不进行交互式变基,您也可以。

As johnb003 mentioned in his comment, when rebasing, ur really making a series of new commits. By doing something such as git log --pretty=oneline --abbrev-commit, you can easily see all the commits you've already made through the rebase. Simply copy their hashes for easy reference later.

正如 johnb003 在他的评论中提到的,在重新定位时,你真的做了一系列新的提交。通过执行诸如 之类的操作git log --pretty=oneline --abbrev-commit,您可以轻松查看已通过 rebase 所做的所有提交。只需复制它们的哈希值,以便稍后参考。

Then git rebase --abort, git rebase -i <base_branch>, copy the hashes you want to preserve, possibly change them to editif you want to modify any of them`, and continue

然后git rebase --abortgit rebase -i <base_branch>复制您要保留的哈希值,edit如果要修改其中任何一个,可以将它们更改为`,然后继续