简体   繁体   English

撤消对 `git rebase -i` 的修正

[英]Undo fixups on a `git rebase -i`

I've seen a few posts here on undoing a git rebase but haven't come across anything that fits my particular case.我在这里看到了一些关于撤消git rebase的帖子,但没有遇到任何适合我的特殊情况的帖子。

I've run the command git rebase -i HEAD~10我运行了命令git rebase -i HEAD~10

After running that, I did fixup to all commits but 3运行之后,我修复了除 3 以外的所有提交

The first 2 commits is code written by someone else here but only on one file, everything else for this branch was written by me across 5 files and I am the author of the latest commit .前 2 次提交是这里其他人编写的代码,但仅在一个文件中,该分支的所有其他内容都是我跨 5 个文件编写的,我是最新提交的作者 All commits between the first 2 and the last 1, I've applied fixup.前 2 和最后 1 之间的所有提交,我都应用了修复。

When I look at VS Code git blame , I see all the code I wrote but it shows the other guy as the author of the code .当我查看 VS Code git blame时,我看到了我编写的所有代码,但它显示另一个人是代码的作者

Is there a way for me to undo the fixup so that I can redo the fixup so that I appear as the author for the code I wrote?有没有一种方法可以让我撤消修复,以便我可以重做修复,这样我就可以作为我编写的代码的作者出现?

An example would be:一个例子是:

git rebase -i HEAD~5

terminal outputs终端输出

pick 12345 Commit 1
pick 12344 Commit 2
pick 12343 Commit 3
pick 12342 Commit 4
pick 12341 Commit 5

I apply the fixup so that it now looks like我应用修复程序,现在看起来像

pick 12345 Commit 1
pick 12344 Commit 2
fixup 12343 Commit 3
fixup 12342 Commit 4
pick 12341 Commit 5

I've now saved these changes.我现在已经保存了这些更改。

When I look at my commit history it shows当我查看我的提交历史时,它显示

Commit 1
Commit 2
Commit 5

My goal is to revert my changes so that when I run我的目标是恢复我的更改,以便在我运行时

git rebase -i HEAD~5 git rebase -i HEAD~5

It should look like this again:它应该再次看起来像这样:

pick 12345 Commit 1
pick 12344 Commit 2
pick 12343 Commit 3
pick 12342 Commit 4
pick 12341 Commit 5

for your case, you should follow these steps.对于您的情况,您应该按照以下步骤操作。

  1. suppose your actual working branch is Master (or dev or any other name).假设您的实际工作分支是Master (或 dev 或任何其他名称)。

  2. find your old commits which you have made a fixup by error, to do that you can run this command找到您错误修复的旧提交,为此您可以运行此命令

    git reflog git 重新登录

  3. suppose now you have found your commits by SHA-1, lets say COMMIT_2 , COMMIT_3 and COMMIT_4假设现在您已经通过 SHA-1 找到了您的提交,假设COMMIT_2COMMIT_3COMMIT_4

  4. checkout the commit before the fixup commits, in your case, it is COMMIT_1在修复提交之前检查提交,在您的情况下,它是COMMIT_1

    git checkout COMMIT_1 git 结帐 COMMIT_1

  5. make a cheery-pick for old commits为旧的提交做一个愉快的选择

    git cherry-pick COMMIT_2 git 樱桃挑选 COMMIT_2

    git cherry-pick COMMIT_3 git 樱桃挑选 COMMIT_3

    git cherry-pick COMMIT_4 git 樱桃挑选 COMMIT_4

  6. now after making cherry-pick for your COMMIT_4 , you should see an other SHA-1 (commit number) for this commit, lets say COMMIT_4'现在,在为您的COMMIT_4进行挑选之后,您应该会看到此提交的另一个 SHA-1(提交编号),比方说COMMIT_4'

  7. go to your working branch go 到您的工作分支

    git checkout Master git 结账师傅

  8. rebase your master on the last cherry-picked commit COMMIT_4'将你的主人重新定位在最后一个精心挑选的提交COMMIT_4'

    git rebase COMMIT_4' git 变基 COMMIT_4'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM