简体   繁体   中英

Rewriting git commit history

Assuming we have a git commit history which looks like:

ZZ [origin/master] A -> B -> C -> D -> E [master]

We want to:

  • Rewind the history back to before A .
  • Keep the working directory of E .
  • Bundle all the changesets of A..E in to a single commit.
  • Push the outcome to remote.

The result should look like:

ZZ -> XX [master][origin/master]

Where XX is the commit encompassing the changes of prior commits A..E

You can try:

git reset --hard E
git reset --soft ZZ
git commit 'comment'
git push orgin master

--soft

Does not touch the index file nor the working tree at all (but resets the head to , just likeall modes do). This leaves all your changed files "Changes to be committed", as git status would putit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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