I'm trying to restore files after a colossal screw up on my part.
git checkout -- *
is working great so far. Except that, for example, in my .gitignore file I have "LICENSE.txt" listed, and it apparently applies not only to the root level file of that name, but every file in the whole directory tree with that name.
So when I run git checkout -- *
in a wordpress folder, it fails with error:
error: pathspec 'blog/license.txt' did not match any file(s) known to git
How can I run the command so that it only applies to tracked files? My other option is to go through every folder and restore files one-by-one.
Also note, license.txt is not my only ignored file problem. There are dozens.
If I understand your question correctly, you want to reset all files that are currently tracked to the previous commit and leave the untracked files alone.
If so, then I would do as follows.
As mentioned by Porges in the comments.
First unstage all your currently modified files:
git reset
Then reset all unstaged modified files to the previous commit.
git checkout -- .
First I would stash the tracked files as follows:
git stash
Then I would stash the untracked files as follows:
git stash -u
Hence, now you have two stashes on your stack: one with tracked files on the bottom and one with untracked files on the top. Pop off the tracked files as follows (aka apply the stash that is second in the stack):
git stash apply stash@{1}
Then reset to the previous commit:
git reset --hard
Finally, apply the untracked files:
git stash apply
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