如何使用 git 取消暂存工作区中的更改?
how to unstage changes in workspace with git?
我正在尝试删除工作区中的 'new file'。当我 运行 'git status' 我得到类似的东西:
..
new file: filepath/filename
untracked files:....
我想取消暂存此文件。我试着 运行 :
git reset HEAD filepath/filename
和:
git checkout filepath/filename
但是当我 运行 git 状态时,没有任何改变,或者新文件仍然显示 '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)
我正在尝试删除工作区中的 'new file'。当我 运行 'git status' 我得到类似的东西:
..
new file: filepath/filename
untracked files:....
我想取消暂存此文件。我试着 运行 :
git reset HEAD filepath/filename
和:
git checkout filepath/filename
但是当我 运行 git 状态时,没有任何改变,或者新文件仍然显示 '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)