1

In one of my Git repos (I'm using Git 1.9.3 on a Mac) I've moved some files from the root directory to one of the subdirectories. As expected when I run git status (in the destination subdirectory) it shows the moved files as deleted from the root directory and the newly added files to the subdirectory as untracked files. I am supposed to do git add --all to record the changes, but I am getting the following message from Git:

$ git add --all
warning: The behavior of 'git add --all (or -A)' with no path argument from a subdirectory of the tree will change in Git 2.0 and should not be used anymore.
To add content for the whole tree, run:

  git add --all :/
  (or git add -A :/)

To restrict the command to the current directory, run:

  git add --all .
  (or git add -A .)

With the current Git version, the command is restricted to the current directory.

What is the difference to the working tree between these two in terms of recording the moved files, and what is the best option in this type of situation?

2 Answers2

1

When moving or deleting files, it's best to make use of git's native tools.

This will delete files from your git repository:

git rm [path]

This will let you move your files from oldpath to newpath, and let you preserve all git history on these files at the same time

git mv [oldpath] [newpath]

When it comes to add files, I generally use the following:

git status
git add *
git commit -m "message"
git push

Status lets me check which files I am adding in. If I want to add all the files, I can use *, otherwise I'll type their individual paths.

As for the error message you got, it is likely because you moved them to a subdirectory that git did not previously know about (i.e you just created it)

aashnisshah
  • 468
  • 4
  • 10
  • In this situation is `git add --all :/` the same as `git add *`? –  Feb 28 '15 at 23:11
  • Based on this post http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add it seems like ```git add *``` adds all files, while ```git add --all``` looks to see if a file had been (manually) moved and matching it up that way. So ```*``` doesn't track information as well. However if you used ```git rm``` and ```git mv``` then ```git add --all``` and ```git add *``` work in essentially the same way – aashnisshah Feb 28 '15 at 23:24
  • I did use `git add --all :/` in the end and did the commit. –  Feb 28 '15 at 23:34
0

In git 2.0, the behavior of git add --all changed. In git < 2.0, it just added the files in your current directory. Since 2.0, it adds every file in the working tree. The message is simply notifying you of this change.

Since you are running git 1.*, you can do one of the following:

  1. Run git add --all from the root of your repository.
  2. Run git add --all :/. The :/ path is a special notation that means "the root directory of the repository".
Justin Howard
  • 5,504
  • 1
  • 21
  • 48