简体   繁体   中英

Using Git add --all after moving files between repo subdirectories

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?

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 (ie you just created it)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM