There is such a situation: you need to remove certain changes from the project. All these changes were made by one commit. Then there were more commits, several of which affected modified files (2 files out of 9). Is it possible with the help of the git to roll back only the changes of the first commit in these files?

  • one
    "One button" I do not know how. But the meaning is this: git revert no-commit, commit the files that need to be reversed, roll back the rest. - Duck Learns to Take Cover

1 answer 1

git revert -n 1234567 // плохой коммит git commit path/to/file -m 'reverted blahblah' // файл который нужно ревертнуть git reset --hard Head // остальное нам не надо 

The meaning is:
1. revert a bad commit, but do not commit canceling changes.
2. Commit canceling changes in the necessary files.
3. We reset everything (that is, files that we don’t want to change) to the state of the last commit (the commit from item 2).

I do it in any gui this is a couple of clicks. Perhaps there are more elegant ways.

  • Is it possible to return changes to only the commit that we want to roll back and leave all the changes that were after the commit, which changes are rolled back? - Pavel Zhukov
  • @GrodasNet, and the current method does not work that way?) Revert reverses changes to a single commit, not the whole tree. - Duck Learns to Take Cover