[英]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.