Santanu C
Santanu C

Reputation: 1392

Git : how to fix a file modification

My experience with git is limited. I am stuck with a problem where I made wrong changes to a couple of files (e.g foo.c and bar.c) and committed. After another commit I realized that my changes were bad. So, the wrong changes with these two files are in HEAD~1. The correct version of these files were checked in to HEAD~5 and HEAD~7 respectively.

What is the recommended way to remove the wrong edits? I tried this :

`git checkout SHA path_to_foo/foo.c`

But it does not actually modify foo.c so that I can create another commit with this.

Upvotes: 0

Views: 42

Answers (1)

kofemann
kofemann

Reputation: 4423

git revert <SHA>

where SHA points to the bad commit. As manual tells:

... revert the changes that the related patches introduce, and record some new commits that record them.

Upvotes: 3

Related Questions