Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (29.3k points)

I currently have three modified files in my working directory. However, I want one of them to be reset to HEAD status.

In SVN I'd use svn revert <filename> (followed by svn update <filename> if needed) but in git I should use git reset --hard. However, this command cannot operate on a single file.

Is there any way in git to discard a single file change and overwrite it with a fresh HEAD copy?

1 Answer

0 votes
by (50.2k points)

You can use the following command:

git checkout HEAD -- my-file.txt

which will update both the working copy of my-file.txt and its state in the index with that from HEAD.

Reference :

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94k users

Browse Categories