git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Difficulty adding a symbolic link, part 2

From
Dale R. Worley <worley@alum.mit.edu>
Date
Jun 25, 2013, 02:36 UTC
Message-ID
<201306250236.r5P2ag85022808@hobgoblin.ariadne.com>

Here's a slightly simpler test case for adding a symbolic link. This test exploits the fact that on my system, /bin/awk is a symbolic link to "gawk". As you can see, the behavior of Git differs if the link's path is given to "git add" as an absolute path or a relative path.

Here is the test script: ---------------------------------------------------------------------- #! /bin/bash

# Illustrates a problem with applying "git add" to a symbolic link.
set -x

# To be run from a directory one step below the root directory. E.g., # "/git-add-link". # Exploits the fact that /bin/awk is a symbolic link to "gawk".

# Show the Git version. git version

# Make a test directory and cd to it. DIR=temp.$$ mkdir $DIR cd $DIR

# Create a Git repository. git init # Set the worktree to be / git config core.worktree / # Create an empty commit. git commit --allow-empty -m Empty.

# Add the symbolic link using its absolute name. ABSOLUTE=/bin/awk ls -l $ABSOLUTE git add $ABSOLUTE # Notice that the target of the link is added, not the link itself. git status -uno

# Reset the index. git reset

# Add the symbolic link using its relative name.
# Remember that we are two directory levels below the root directory now.
RELATIVE=../..$ABSOLUTE
ls -l $RELATIVE
git add $RELATIVE
# Notice that now the link itself is added.
git status -uno
----------------------------------------------------------------------
Here is the output of the script:
----------------------------------------------------------------------
+ git version
git version 1.7.7.6
+ DIR=temp.22366
+ mkdir temp.22366
+ cd temp.22366
+ git init
Initialized empty Git repository in /git-add-link/temp.22366/.git/
+ git config core.worktree /
+ git commit --allow-empty -m Empty.
[master (root-commit) fb232e5] Empty.
+ ABSOLUTE=/bin/awk
+ ls -l /bin/awk
lrwxrwxrwx. 1 root root 4 Nov  2  2012 /bin/awk -> gawk
+ git add /bin/awk
+ git status -uno
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   ../../bin/gawk
#
# Untracked files not listed (use -u option to show untracked files)
+ git reset
+ RELATIVE=../../bin/awk
+ ls -l ../../bin/awk
lrwxrwxrwx. 1 root root 4 Nov  2  2012 ../../bin/awk -> gawk
+ git add ../../bin/awk
+ git status -uno
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   ../../bin/awk
#
# Untracked files not listed (use -u option to show untracked files)
----------------------------------------------------------------------
I can't see any principle of operation of Git that would cause "git
add /bin/awk" and "git add ../../bin/awk" to be handled differently.
Dale
Message 1 of 1 in “Difficulty adding a symbolic link, part 2”
  1. Dale R. WorleyJun 25, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.