0

I have created file and symbolic link to file in my git repository.
symfile1 --> file1
When I change file1, I can see history of change by git log file1,
but I don't see the same history when I do git log symfile1
Is there any way to see history change of real file, using git log to it's symbolic link?

The questions is related only history can I see the history change of file1 using symbolik1 ?

Suren
  • 47
  • 2
  • 10
  • Possible duplicate of [How does git handle symbolic links?](http://stackoverflow.com/questions/954560/how-does-git-handle-symbolic-links) – DevDonkey Apr 17 '17 at 08:46
  • Possible duplicate of [How can I get git to follow symlinks?](http://stackoverflow.com/questions/86402/how-can-i-get-git-to-follow-symlinks) – sschuberth Apr 17 '17 at 09:04
  • You just have to inspect `symfile1`, see that it *is* a symbolic link, see if the target of the link is in the repository, and then look at the history of the target of the link (assuming the target is in the repository; if not, the history of the target file isn't in the repository). – torek Apr 17 '17 at 11:53
  • thanks for reply, is it possible to hook git log? – Suren Apr 17 '17 at 12:55

2 Answers2

2

No. The symbolic link has not changed at all, it still points to the same destination. Neither can git tell you, not should it. If I would see git flagging a change on a symbolic link, the only if the link were now pointing to a different file name. Symbolic links generally are only concerned with file names, not file contents.

That said, you can create a short bash script which does that. Then you can create a git alias for it -scm.com/book/tr/v2/G . The script can use standard bash features to find the link target and then call the proper git command you want.

AnoE
  • 8,048
  • 1
  • 21
  • 36
  • Isn't there any way to say git(any option) that I wan't to see the history of the file which sym link pointing to? – Suren Apr 17 '17 at 11:15
  • No. You could write a shell script that does it for you, but git itself does not. – AnoE Apr 17 '17 at 13:09
  • Not sure what you mean by "hook git log". What exactly is it that you *really* wish to achieve, @suren? – AnoE Apr 17 '17 at 13:38
  • the point is when I call git log "file", it will hook and call shell script which will check if the given file is sym link or not, in case if it is sym link I can add functionality in script to show the history of file which it is refered to. Is it possible? – Suren Apr 17 '17 at 13:47
  • Ah ok, it seems there is misunderstanding. by hook git log I mean the mechanism to execute script when using git log command, for e.g there is hook mechanism for handle some git commands (in .git/hooks pre-push.sample, pre-commit.sample, post-update.sample ...). I wonder if there is a way to do the same for git log? – Suren Apr 17 '17 at 15:22
  • No, not for git log. – AnoE Apr 17 '17 at 15:37
1

Just to add..

GIT treats a symbolic link the same as it does any file, but it stores the contents of the link it relates to. What it doesn't do, is follow the link and then consider the target. In fact, it has no clue about the target other than the value of the link that it contains.

when you checkout, GIT will recreate that symbolic link, with its original file path, but it wont consider the target file at all (unless thats also in version control, but it will be tracked independently of the symlink).

Think of it as a shortcut on the desktop, which is a file. Put that into version control and it'll track the shortcut, not the thing it points to.

DevDonkey
  • 4,835
  • 2
  • 27
  • 41