Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

Undoing a git rebase --skip - reapply a commit during a rebase

I'm doing a long git rebase with a lot of commits. I accidentally --skipped a commit where there were some conflicts which I resolved. I should have done git rebase --continue.

Is there are way to re-apply this previous commit during this rebase phase and then continue the rebase?

One way I see is to

  1. stop the rebase at this point by creating a branch on the last commit which was correctly applied
  2. restart the rebase starting with the previously skipped commit.

Or can I do a cherry-pick whilst being in a rebase-phase?

question from:https://stackoverflow.com/questions/21705323/undoing-a-git-rebase-skip-reapply-a-commit-during-a-rebase

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found a way which "worked for me":

During a rebase lots of things are happening in the .git/rebase-apply directory. Amongst others there is a file called next. next is containing a number which corresponds to a file which is residing in the .git/rebase-apply as well. This file contains information about the commit which is currently being processed. For example:

$ cat .git/rebase-apply/next
0260
$ less .git/rebase-apply/0260
<info about the commit which is currently processed (and has conflicts)

Git seems to keep the commits which are skipped as the above mentioned files. Whereas files corresponding to commits which have been applied are not there anymore. The commit I accidentally skipped was called 0259 and the file was still present.

Here is what I did:

$ echo "0258" > .git/rebase-apply/next

With that I told git that currently the 258th commit is processed (which previous applied correctly). Then I did

$ git rebase --skip

to tell git to forget this one and, voila, I could again work on the skipped commit, correct the conflicts and --continue. It has worked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...