简体   繁体   中英

Revert last commit for one file and not the whole repo

I have a repo that has many commits. In Intellij I can see the commits that affected a file and the last three are mine. These commits are buried inside a long history of commits, but for that specific file they are the last three commits.

Is it possible to revert commits for one specific file?

I guess the simplest thing you can do is to take back that specific file to how it was before the first of the 3 last revisions you are talking about.... too bad you won't be able to link to those 3 revisions.... but you might address them in the revision comment. So...

git checkout earliest-of-the-three-revisions~ -- path-to-file
git commit -m "Reverting file path-to-file

revisions x, y and z produced and undesired effect because of foo bar"

And that should be it.

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