1

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 .?

Vineet
  • 413
  • 4
  • 6

2 Answers2

1

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?

Community
  • 1
  • 1
Igal S.
  • 13,146
  • 5
  • 30
  • 48
0

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

Dawn T Cherian
  • 4,968
  • 3
  • 24
  • 35