【问题标题】:How to avoid deleting local files when igoring and deleting files on a Github repository?如何避免在 Github 存储库中删除和删除文件时删除本地文件?
【发布时间】: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


    【解决方案1】:

    我不相信这是可能的。见Git: How to remove file from index without deleting files from any repository

    还可以考虑使用git-extras 中的git-lock,或者直接使用git update-index --skip-worktree 而不是从存储库中删除,以忽略本地更改(如果这类似于配置文件)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-19
      • 2016-07-03
      • 2011-12-25
      • 2018-06-25
      • 2023-04-09
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多