2016-04-13 94 views
1

我在中央遠程存儲庫中有一些文件。我曾經犯過這些事。他們不需要被追蹤了。我將它們添加到我的.gitignore文件中。但我仍然需要他們在我本地的回購,爲我的本地網站。從遠程回購中刪除提交的文件,但保留它們在本地

我該怎麼做,讓他們離開我的遠程倉庫,但仍然保留在我的本地存儲庫?

回答

1

[編輯]

你必須從混帳與git rm --cached foo.txt刪除它們。這會將它們標記爲已在回購中刪除,但不會實際刪除它們。

所以,這是一個完整的打印出來:

master!git> git status 
On branch master 
nothing to commit, working directory clean 
master!git> ls -la 
total 0 
drwxr-xr-x 4 creynder staff 136 Apr 13 13:14 . 
[email protected] 52 creynder staff 1768 Apr 13 13:14 .. 
drwxr-xr-x 12 creynder staff 408 Apr 13 13:14 .git 
-rw-r--r-- 1 creynder staff  0 Apr 13 13:14 foo.txt 
master!git> git rm --cached foo.txt 
rm 'foo.txt' 
master!git *> git status 
On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    deleted: foo.txt 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    foo.txt 

master!git *> git commit -m 'Delete foo.txt' 

然後添加 「foo.txt的」 來的.gitignore。

相關問題