I've previously been able to undo changes through SourceTree by performing the "Discard" function, which under the hood produces this command:
git -c diff.mnemonicprefix=false -c core.quotepath=false reset -q HEAD -- myproj.csproj
git -c diff.mnemonicprefix=false -c core.quotepath=false checkout HEAD -- myproj.csproj
Suddenly this doesn't work. I do the Discard, no error occurs, refreesh the view, but the files are still "modified". I've then tried to do the same in the command line with the following, same result:
c:\myproject> git reset HEAD
Unstaged changes after reset:
M myproj.csproj
Why is it still listed as an unstaged change?
I've verified that the file is indeed writable (no process is holding a lock)
update
git checkout
didn't work either:
C:\myproject>git checkout myproj.csproj
C:\myproject>git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: myproj.csproj
#
no changes added to commit (use "git add" and/or "git commit -a")
Update 2 Also tried:
git checkout --
git checkout -- .
git checkout HEAD
,none of which solves my problem
update 3 - huge step closer:
Turns out when I do the checkout, the .csproj is indeed reverted to the correct version, but the checked out version uses a different line feed encoding. While the checked-in version has CR-LF (0D-0A) for line feed, the checked-out has only LF (0A). Hence git belives the file to be different on every single line. Why this?
update 4: added the second line of git-commands issued by SourceTree. I didn't notice that the first time around, that's why I thought git reset HEAD
would do anything. This doesn't change the fact that the underlying problem still is CR/LF-related (I think)
summary I never found a solution to the issue, but I "solved" it by checking in the file. My original question didn't contain information that SourceTree indeed issued the correct commands to rollback what I wanted, so most answers here address that issue. The real issue is still unclear, but my main theory is that it was CR/LF related.
Git stash lets you discard changes and save them for later reuse. Try Git checkout --<file> to discard uncommitted changes to a file. Git reset --hard is for when you want to discard all uncommitted changes. Use Git reset --hard <commit id> to point the repo to a previous commit.
We can use the command git fsck to recover the files after a hard reset.
For all unstaged files in current working directory use: git restore . That together with git switch replaces the overloaded git checkout (see here), and thus removes the argument disambiguation. If a file has both staged and unstaged changes, only the unstaged changes shown in git diff are reverted.
git reset --hard resets your index and reverts the tracked files back to state as they are in HEAD. It leaves untracked files alone.
If you need to remove local changes then run following command
git checkout -- file_name
git reset HEAD
does not remove local changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With