添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
痛苦的双杠  ·  [RN/Android] Git pull ...·  5 天前    · 
直爽的荔枝  ·  Git | ...·  5 天前    · 
追风的水煮鱼  ·  wolfcrypt: the ...·  6 天前    · 
想表白的茶壶  ·  Gitlab-runner ...·  1 周前    · 
小眼睛的帽子  ·  3.3.4.5 Date ...·  1 月前    · 
淡定的熊猫  ·  3 个鲜为人知的 Postman ...·  1 月前    · 
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.

What exactly are you trying to achieve with git checkout -- * ? Maybe there's a better way to achieve that, perhaps with git reset --hard ? Steve Bennett Dec 11, 2015 at 3:19 @SteveBennett Maybe git reset --hard would have worked at that point too. It was a big mess. I lost some essential untracked files, so I had to restore from a backup that was mostly the same, but had a few differences. I was using git checkout * to restore the files that still showed as changed with git status . Buttle Butkus Dec 11, 2015 at 6:14

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
                This looks really good, but when I run git stash -u I get an error "unknown option for 'stash save': -u". I'm on git version 1.7.1 running on Centos 6.
– Buttle Butkus
                Dec 11, 2015 at 3:33
                I just installed it a few weeks ago. I guess CentOS is behind as usual. Is your method better than using git checkout -- . in the root directory?
– Buttle Butkus
                Dec 11, 2015 at 3:37
                I've upgraded to 2.0.4 so now I can do your way as well. But git checkout -- . is much simpler, if it accomplishes the same thing.
– Buttle Butkus
                Dec 11, 2015 at 6:05
        

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.