繁体   English   中英

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

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

我试图摆脱工作区中的“新文件”。 当我运行'git status'时,我得到类似的东西:

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

我想取消暂存此文件。 我试着跑:

git reset HEAD filepath/filename

和:

git checkout filepath/filename

但是,当我运行git status时,没有任何更改,或者新文件仍然显示消息“new file ..”(见上文)。 我如何摆脱这个文件,以便我可以推动我的其余代码?

git status周围还有更多输出吗?

当我运行场景时, 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