1

TLDR

I want to be able to have two files change simultaneously in different projects.

Long version

I would like to use git to ONLY track content changes to my files, I do not care about so called typechange changes. Can I change my git configuration or edit my .gitignore file?

I have a file ~/proj/real_foo that has identical contents to the tracked ./foo but I want to be able to have both files change simultaneously in different projects.

Currently:

> 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")

Desired:

> 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
Lenna
  • 1,220
  • 6
  • 22
  • 1
    Does this answer your question? [How do I make Git ignore file mode (chmod) changes?](https://stackoverflow.com/questions/1580596/how-do-i-make-git-ignore-file-mode-chmod-changes) – Jim Jun 02 '20 at 17:37
  • Partially yes, that helped with my ```mode``` change question but not my ```typechange``` question. – Lenna Jun 02 '20 at 18:04

1 Answers1

2

Git doesn't provide a way to ignore type changes. This is a specific case of the more general case of ignoring changes to tracked files, to which the answer is, Git doesn't offer that as an option. Trying to use one of the git update-index suggestions typically offered doesn't work, as the documentation states.

What you can do here is to ignore foo and provide some template for it that's copied over by your build system or a script if it doesn't exist. Since a symlink exists, it will be preserved, while still making the code work on a fresh clone with a plain file. You could also have your build system or script just symlink to the template file instead.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • This answer makes me sad. I am not sure if it's true though, it's hard to know if something is actually impossible. – Lenna Jun 03 '20 at 02:38
  • 1
    I'm a major contributor to Git and I wrote the documentation I linked to. Certainly I'm open to hearing ways that people might try to do it, but absent someone thinking of something I haven't, I don't think it's going to work. – bk2204 Jun 03 '20 at 03:10
  • I respect that some things actually cannot be done. I will keep this post open for a bit and accept your answer if nobody comes up with a solution. I was hoping there might be some way to reference one file from another repo.. kind of like a single file sub-module? But be able to change the contents of that file in both repos. – Lenna Jun 03 '20 at 12:03
  • 1
    @Lenna: it's true. You can use `git update-index --assume-unchanged` or `git update-index --skip-worktree` and it will do *some* good *sometimes* but it is a painful way to work. – torek Jun 03 '20 at 15:23