Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
First way
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 -- .
Second way (Git 1.7.7+ only)
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
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.