Vineet
Vineet

Reputation: 463

git: Revert back file from commit

I have committed a file with some changes. But now i don't want that changes so how should i revert back to original file keeping other files changes for next commit.

ex: file1.c file2.c file3.c

I made changes in all three files and committed.
Now i don't want file1.c changes, i want as of original. i tried below but its not working.

git checkout HEAD^ file1.c git checkout file1.c git commit --amend

What else i am missing .?

Upvotes: 1

Views: 99

Answers (2)

Dawn T Cherian
Dawn T Cherian

Reputation: 5426

If there are only few changes, manually edit file1.c(back to state before commit) and commit that file again.

Upvotes: 0

Igal S.
Igal S.

Reputation: 14593

You should reset the file to the version you want and then commit it.

git reset HEAD^ file1.c
git add file1.c
git commit --amend

A second option would be to reset the entire tree to previous state and just don't commit the file

git reset HEAD^
git add file2.c git add file3.c
git commit

See much longer discussion here: Reset or revert a specific file to a specific revision using Git?

Upvotes: 1

Related Questions