4

I recently added and committed a symbolic link to a text file (in an external directory) to a git repository. I expected this would commit the innards to the text file. However, when I cloned the repository to a second machine, the symbolic link was indeed still a symbolic link. It was now pointing at an unrelated text file (of the same name) on the second machine. My question is, why and how did git behave in this way?

Why is it possible to commit the actual link itself and when might this be useful?

Thank you!

T.Lipperz
  • 581
  • 2
  • 5
  • 7

1 Answers1

4

In a nutshell, git add files for what they are (file, symlink, directory). This is usually fine if the symlink target is also in the source control, or at least in a known location.

If that conflicts with what you want to do, I'd first consider why you'd want the file be a symlink, and still be in version control in the first place. Chances are, you'll probably discover that you don't.

There is number of discussions about this here already, including some that explain why this is so, and how to work around it.

Community
  • 1
  • 1
averell
  • 3,762
  • 2
  • 21
  • 28
  • 4
    Thanks but I did not ask, "are committing symbolic links to git useful?" I was looking for an explanation of git operations. – T.Lipperz Apr 19 '16 at 13:23
  • 2
    Well, I did say that git commits symlinks as symlinks - something that you already found out. You asked about the reason why that was so. Also, for some reason, part of my response had been truncated... Anyway, I added link to another article that discusses that topic. As symlinks and git are already widely covered on SO, I leave it there. – averell Apr 20 '16 at 13:22