I have 2 files that are in my working directory. I want to completely discard these files so I can switch branches.
There are many helpful guides online, and I have tried every answer I can find to remove these files, yet they still persist.
user@machine:~/Code/foo$ git status
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: src/test/foo.c
modified: src/test/bar.c
Commands I have tried based on other stackoverflow questions.
git reset
git reset --hard HEAD^
git stash save --keep-index
git stash drop
git checkout HEAD -- $(git ls-files -m)
git clean -f
git clean -dfx
git checkout -- .
git checkout -- *
git checkout 123456
git reset --hard 123456
git reset HEAD --hard
Amazingly, after every command, I find the files are still present!
user@machine:~/Code/foo$ git status
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: src/test/foo.c
modified: src/test/bar.c
Since there are only 2 files, I know I could just recheck them out one by one. However if this happened again and I had 100 files, I want to know the procedure to blow all of them away in one sweep.
git checkout src/test/foo.c
git checkout src/test/bar.c
Update
Aparently not even a git checkout works
git checkout src/test/foo.c
echo $?
0
git checkout src/test/bar.c
echo $?
0
user@machine:~/Code/foo$ git status
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: src/test/foo.c
modified: src/test/bar.c
These files just wont go away.
Update2
I've tried these command as well with no luck.
git reflog
git checkout HEAD@{17}
git init
git reset --hard HEAD^
Update3
Stashing does nothing.
git checkout master
git stash
git stash pop
git stash drop
Deleting the files does not work either.
user@machine:~/Code/foo$ git rm --cached $(git ls-files -m)
rm 'src/test/foo.c'
rm 'src/test/bar.c'
user@machine:~/Code/foo$ git status
On branch master
Your branch is behind 'origin/master' by 162 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: src/test/foo.c
deleted: src/test/bar.c