brannerchinese
brannerchinese

Reputation: 1999

Git — tracking the moving of already tracked files

Mercurial has a single command addr that stages both added and removed paths, so it is able to track the moving of a given file to a different path in the directory.

To do this in Git, I find I have to use two separate commands:

git add -u <path>

will note the disappearance of those files from their original path, and then

git add <path>

will note their appearance somewhere else.

But there doesn't seem to be a one-step equivalent to Mercurial's addr command. Or am I mistaken?

Upvotes: 0

Views: 53

Answers (1)

user456814
user456814

Reputation:

Git has a move command that can be used to move files/folders:

git mv <file or directory> <destination>

You can also use the --all or -A flag of add to update both new files and removed files in the index

git add -A

From the official Linux Kernel Git documentation for git add (emphasis mine):

-A
--all

Like -u, but match <filepattern> against files in the working tree in addition to the index. That means that it will find new files as well as staging modified content and removing files that are no longer in the working tree.

Upvotes: 3

Related Questions