【发布时间】:2015-03-26 03:09:24
【问题描述】:
假设我有一个现有的 Github 存储库和该存储库的多个本地克隆。
现在我决定阻止某个文件被 Git 管理,并从 Github 存储库中删除该文件。我在其中一个本地克隆中执行了以下命令:
echo "to_be_ignored_file_name" >> .gitignore
git add .
git commit -m 'make git ignore a certain file'
git rm -r --cached .
git add .
git commit -m "delete the file to be ignored from the repository"
git push origin
完成上述操作后,该文件已从 Github 存储库中删除,Git 将从现在开始忽略该文件。但是结果,该文件的本地副本也被删除了(对于其他克隆,该文件在git fetch origin和git pull之后被删除)。
如果我将上述命令序列的第二部分替换为如下:
git rm --cached to_be_ignored_file_name
git commit -m "delete the file to be ignored from the repository"
git push origin
然后执行命令序列的克隆中的本地文件未受影响,但在git fetch origin和git pull之后,其他克隆中的相同文件仍然被删除。
有没有办法在所有克隆中保持本地文件不变,同时忽略和删除 Github 存储库中的文件?
【问题讨论】:
标签: git github version-control gitignore