简体   繁体   中英

How can i undo changes between two commits?

I want revert one file changes between two commit,

commit 1 hash: abcde1....
   some code changes

commit 2 hash : abcde2....
   some code changes

commit 3 hash : abcde3....
   some code changes

.....

i can use git checkout abcde3 -- file/to/restore and revert to commit 3, but lost commit 1 changes,
How can i checkout only commit 2 changes?

You can simply use git revert .

Revert commit 2, and that will create a new commit which cancels any changes introduced by said commit 2.

If git revert (which operates at the commit level, and not for a single file) reverts too many file, you can reset the files you did not want reverted .

git revert --no-commit <commit hash> # Revert, don't commit it yet
git reset # Unstage everything
git add yourFilesToRevert # Add the file to revert
git commit -m "commit message"
git reset --hard # Undo changes from the part of the revert that we didn't commit

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