GIT 使用排除本地更改忽略已提交的文件
GIT Ignore already commited files using exclude for local changes
我克隆了包含三个文件的远程存储库
file1.txt
file2.txt
file3.txt
在我的机器上本地更改为 file3.txt。我不希望更改进入远程仓库,反之亦然。
我读到使用 .gitignore 无法忽略已经提交和跟踪的文件。
我决定使用带有以下行的 .git/info/exclude 文件
排除文件
file3.txt
但在 file3.txt 中所做的更改仍然显示为未暂存文件。我希望这个 file3.txt 在提交和暂存中被忽略,还需要防止 file3.txt 从远程仓库更新
在此先感谢您的帮助
编辑 .gitignore 文件,添加以下行:
file3.txt
I read that using .gitignore it is not possible to ignore the already commited and tracked file.
是,与.gitignore
或.git/info/exclude
。
你只需要先记录那个文件的删除即可。
git rm --cached file3.txt
一旦删除(仅从缓存中,而不是从硬盘驱动器中),git status
不应显示它(因为它已经在 .gitignore
中)
参见““git rm --cached x
” vs “git reset head — x
”?”:"cache",也称为 "index" 或 "staging area",仅从索引中删除文件并将其保留在您的工作副本中。
file3.txt
将不再在 repo 中进行版本控制。
一旦删除被提交并推送,这将传播到其他克隆。
如果您只需要 ignore the file locally 一段时间,您可以试试:
git update-index --assume-unchanged -- file3.txt
注意:根本不涉及 .gitignore
。
要停止在本地忽略更改:
git update-index --no-assume-unchanged -- file3.txt
我克隆了包含三个文件的远程存储库
file1.txt
file2.txt
file3.txt
在我的机器上本地更改为 file3.txt。我不希望更改进入远程仓库,反之亦然。
我读到使用 .gitignore 无法忽略已经提交和跟踪的文件。
我决定使用带有以下行的 .git/info/exclude 文件
排除文件
file3.txt
但在 file3.txt 中所做的更改仍然显示为未暂存文件。我希望这个 file3.txt 在提交和暂存中被忽略,还需要防止 file3.txt 从远程仓库更新
在此先感谢您的帮助
编辑 .gitignore 文件,添加以下行: file3.txt
I read that using .gitignore it is not possible to ignore the already commited and tracked file.
是,与.gitignore
或.git/info/exclude
。
你只需要先记录那个文件的删除即可。
git rm --cached file3.txt
一旦删除(仅从缓存中,而不是从硬盘驱动器中),git status
不应显示它(因为它已经在 .gitignore
中)
参见““git rm --cached x
” vs “git reset head — x
”?”:"cache",也称为 "index" 或 "staging area",仅从索引中删除文件并将其保留在您的工作副本中。
file3.txt
将不再在 repo 中进行版本控制。
一旦删除被提交并推送,这将传播到其他克隆。
如果您只需要 ignore the file locally 一段时间,您可以试试:
git update-index --assume-unchanged -- file3.txt
注意:根本不涉及 .gitignore
。
要停止在本地忽略更改:
git update-index --no-assume-unchanged -- file3.txt