简体   繁体   English

在回购子目录之间移动文件后,使用Git add --all

[英]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. 在我的一个Git仓库中(我在Mac上使用的是Git 1.9.3),我已经将一些文件从根目录移到了一个子目录中。 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. 正如我期望的那样,当我运行git status (在目标子目录中)时,它将移动的文件显示为从根目录中deleted ,而新添加的文件显示为未跟踪的文件到子目录中。 I am supposed to do git add --all to record the changes, but I am getting the following message from Git: 我应该做git add --all来记录更改,但是我从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. 移动或删除文件时,最好使用git的本机工具。

This will delete files from your git repository: 这将从git存储库中删除文件:

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 这将使您将文件从oldpath移至newpath ,并同时保留这些文件上的所有git历史记录

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. Status使我可以检查要添加的文件。如果要添加所有文件,可以使用* ,否则将键入它们的单独路径。

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) 至于收到的错误消息,可能是因为您将它们移到了git以前不知道的子目录中(即,您刚刚创建了它)

In git 2.0, the behavior of git add --all changed. 在git 2.0中, git add --all的行为已更改。 In git < 2.0, it just added the files in your current directory. 在git <2.0中,它只是将文件添加到当前目录中。 Since 2.0, it adds every file in the working tree. 从2.0开始,它将每个文件添加到工作树中。 The message is simply notifying you of this change. 消息只是在通知您此更改。

Since you are running git 1.*, you can do one of the following: 由于您正在运行git 1. *,因此可以执行以下操作之一:

  1. Run git add --all from the root of your repository. 从存储库的根目录运行git add --all
  2. Run git add --all :/ . 运行git add --all :/ The :/ path is a special notation that means "the root directory of the repository". :/路径是一个特殊的符号,表示“存储库的根目录”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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