Git reset single file in feature branch to be the same as in master

Git

Git Problem Overview


I'm trying to revert my changes in a single file in my feature branch and I want this file to be the same as in master.

I tried:

git checkout -- filename
git checkout filename 
git checkout HEAD -- filename

It seems that none of these made any changes to my feature branch. Any suggestions?

Git Solutions


Solution 1 - Git

If you want to revert the file to its state in master:

git checkout origin/master [filename]

Solution 2 - Git

you are almost there; you just need to give the reference to master; since you want to get the file from the master branch:

git checkout master -- filename

Note that the differences will be cached; so if you want to see the differences you obtained; use

git diff --cached

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnton BelevView Question on Stackoverflow
Solution 1 - GitDennan HogueView Answer on Stackoverflow
Solution 2 - GitChris MaesView Answer on Stackoverflow