Git 忽略类型更改

Git ignore typechanges

TLDR

我希望能够在不同的项目中同时更改两个文件。

长版

我想使用 git 仅跟踪我的文件的内容更改,我不关心所谓的 typechange 更改。我可以更改我的 git 配置或编辑我的 .gitignore 文件吗?

我有一个文件 ~/proj/real_foo 与跟踪的 ./foo 具有相同的内容,但是 我希望能够在不同的项目中同时更改这两个文件。

目前:

> ls
foo
> git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
> rm foo; ln -s ~/proj/real_foo ./foo
> git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    typechange: foo

no changes added to commit (use "git add" and/or "git commit -a")

期望:

> ls
foo
> git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
> rm foo; ln -s ~/proj/real_foo ./foo
> git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Git 不提供忽略类型更改的方法。这是忽略对跟踪文件的更改的更一般情况的特定情况,答案是 Git 不提供该选项。尝试使用 git update-index 通常提供的建议之一 doesn't work,如文档所述。

您在这里可以做的是忽略 foo 并为其提供一些由您的构建系统或脚本复制的模板(如果它不存在)。由于符号链接存在,它将被保留,同时仍然使代码在带有纯文件的新克隆上工作。您也可以让您的构建系统或脚本只是指向模板文件的符号链接。