2015-02-24 89 views
0

我想擺脫我的工作區中的'新文件'。當我運行「git的狀態:」我得到的東西,如:如何使用git來暫停工作區中的更改?

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

我想unstage此文件。我試圖運行:

git reset HEAD filepath/filename 

和:

git checkout filepath/filename 

但是當我運行的git狀態沒有任何改變或新文件仍然出現消息「的新文件..」(見上文)。我怎樣才能擺脫這個文件,所以我可以推我的代碼的其餘部分?

+2

'git的RM文件路徑--cached/filename' – 2015-02-24 05:53:24

+0

如果你想從你的工作目錄刪除該文件,離開了'--cached'。使用'--cached'停止跟蹤文件,但將其保留在工作目錄中。另外,爲了將來的參考,您可以使用'git reset --filepath/filename'來取消下一次提交的暫存更改。 – 2015-02-24 06:10:04

回答

0

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)