简体   繁体   English

如何使用git取消工作区中的更改?

[英]how to unstage changes in workspace with git?

I am trying to get rid of a 'new file' in my workspace. 我试图摆脱工作区中的“新文件”。 When I run 'git status' I get something like: 当我运行'git status'时,我得到类似的东西:

..
    new file: filepath/filename
    untracked files:....

I would like to unstage this file. 我想取消暂存此文件。 I tried to run : 我试着跑:

git reset HEAD filepath/filename

and: 和:

git checkout filepath/filename

But when I run git status nothing is changed or the new file still appears with the message 'new file..' (see above). 但是,当我运行git status时,没有任何更改,或者新文件仍然显示消息“new file ..”(见上文)。 How can I get rid of this file so I can push the rest of my code? 我如何摆脱这个文件,以便我可以推动我的其余代码?

Is there any more output around the git status ? git status周围还有更多输出吗?

When I run the scenario, git status suggests using git reset HEAD path/to/file , which works: 当我运行场景时, git status建议使用git reset HEAD path/to/file ,它的工作原理如下:

my-mac:my_repo acanby$ echo "test file" > test.txt
my-mac:my_repo acanby$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test.txt

nothing added to commit but untracked files present (use "git add" to track)
my-mac:my_repo acanby$ git add test.txt 
my-mac:my_repo acanby$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   test.txt

my-mac:my_repo acanby$ git reset HEAD test.txt
my-mac:my_repo acanby$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test.txt

nothing added to commit but untracked files present (use "git add" to track)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM