我克隆了一个包含一些.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/
只需调用git-rm-缓存在要从修订控制中删除的每个文件上就可以了。只要本地忽略模式正确,您就不会在git状态的输出中看到这些文件。
请注意,此解决方案从存储库中删除文件,因此所有开发人员都需要维护自己的本地(非版本控制)文件副本
要防止git检测到这些文件中的更改,还应使用以下命令:
git update-index --assume-unchanged [path]
你可能想做什么:(从下面@Ryan Taylor回答)
这是为了告诉git您想要自己的独立版本的文件或文件夹。例如,您不想覆盖(或删除)生产/登台配置文件。git更新索引--跳过工作树<路径名>
完整答案在以下URL中:http://source.kohlerville.com/2009/02/untrack-files-in-git/
为了忽略对目录中所有文件(特定类型)的任何更改,我必须结合这些方法,否则如果文件以前不存在,就会创建这些文件。
在下面,“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/