我克隆了一个包含一些.csproj文件的项目。我不需要/喜欢我的本地csproj文件被Git跟踪(或在创建补丁时被提起),但很明显,项目中需要这些文件。
我已经将*.csproj添加到我的LOCAL.gitignore中,但文件已经在repo中。
当我键入gitstatus时,它显示了我对csproj的更改,我对跟踪或提交补丁程序不感兴趣。
如何从我的个人存储库中删除这些文件的“跟踪”(但将它们保存在源中,以便我可以使用它们),以便我在执行状态(或创建补丁)时不会看到更改?
是否有正确/规范的方法来处理这种情况?
为了忽略对目录中所有文件(特定类型)的任何更改,我必须结合这些方法,否则如果文件以前不存在,就会创建这些文件。
在下面,“excludedir”是我不希望看到更改的目录的名称。
首先,从更改跟踪缓存中删除任何现有的新文件(而不从文件系统中删除)。
git status | grep "new file:" | cut --complement -d " " -f1-4 | grep "^excludedir" | xargs git rm --cache
您可以使用modified:执行相同操作。重命名:有点复杂,因为您必须查看新文件名的post->位,然后按照下面对delete:的描述执行pre->位。
deleted:文件证明有点复杂,因为您似乎无法更新本地系统上不存在的文件的索引
echo .deletedfiles >> .gitignore
git status | grep "deleted:" | cut --complement -d " " -f1-4 | grep "^excludedir" > .deletedfiles
cat .deletedfiles | xargs -d '\n' touch
cat .deletedfiles | xargs -d '\n' git add -f
cat .deletedfiles | xargs -d '\n' git update-index --assume-unchanged
cat .deletedfiles | xargs -d '\n' rm
上面列表中的最后一个命令将再次从您的文件系统中删除文件,因此请随意省略。
然后,阻止该目录中的更改跟踪
git ls-files excludedir/ | xargs git update-index --skip-worktree
git update index --skip-worktree excludedir/