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
785 views
in Technique[技术] by (71.8m points)

git rewrite history - how to re-order commits in Git non-interactively

What non-interactive git command(s) achieve the change from Before to After?

Before:

A---B---C---D

After:

A---C'---B'---D'
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

In your case, you can rebase interactive: git rebase -i HEAD~4 Then you can just reorder your picks

For example lets add three more files to our branch:

git add A
git commit -m "A"

git add B
git commit -m "B"

git add C
git commit -m "C"

Your shortlog will be:

$ git shortlog
 (3):
      A
      B
      C

If you want to reorder B with C:

$ git rebase -i HEAD~2
pick 1f9133d B
pick 33f41be C

You just re-order them to be:

pick 33f41be C
pick 1f9133d B

After you're done writing, see the shortlog:

$ git shortlog
 (3):
      A
      C
      B

You can do the same thing with all the commits by re-ordering. It is like what you see is what you get, which is pretty cool :)


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

...