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

Re: rm and mv commands: should I use them?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jan 6, 2008, 19:22 UTC
Message-ID
<alpine.LFD.1.00.0801061108320.2811@woody.linux-foundation.org>
In-Reply-To
<379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com>
On Sun, 6 Jan 2008, Jon Hancock wrote:
> 
> So, do I need to use git's mv and rm commands?
Nope.
They are there only to
 (a) make people who are used to do "svn mv" not complain
 (b) simplify things a little teeny bit, by avoiding having to "git add" 
     the new file.
So if you do just a rename, you can do either
	git mv old-file new-file
	git commit
or you can do
	mv old-file new-file
	git add new-file
	git commit -a

and the *result* will be the same (the "git commit -a" is there to automatically pick up the fact that "old-file" went away: you could have done it with "git rm old-file" too, or "git add -u" or any number of other ways that update the index).

> Can't I just rename, add, and remove files using any means I like and 
> then just ensure my "index" is staged properly when I do a commit?

Absolutely. And depending on your workflow, that may well be the right thing to do.

In particular, this all means that it's perfectly fine to make changes to a git repository using *any* non-git-aware tools, including things like graphical file managers etc.

> Additionally, is there a simple procedure with git to say: "I want to 
> version exactly what is in my working tree.  If I removed something or 
> added something, just handle it".  This is sort of what "git add ." 
> does, but "git add" doesn't handling things I removed or moved, correct?
You should be able to do that with either
	git add .
	git commit -a
or if you don't want to do a commit, you can do a
	git add -u
	git add .

where the "git add -u" will look at any files git already knows and update them (which includes removing them if they are gone), and then "git add ." will add any new files.

		Linus
Previous: Jeff KingNext: Jeff King
Message 5 of 11 in “rm and mv commands: should I use them?”
  1. Jon HancockJan 6, 2008
  2. David BrownJan 6, 2008
  3. Brian SwetlandJan 6, 2008
  4. Jeff KingJan 6, 2008
  5. Linus TorvaldsJan 6, 2008
  6. Jeff KingJan 7, 2008
  7. Junio C HamanoJan 7, 2008
  8. Jeff KingJan 7, 2008
  9. Robin RosenbergJan 7, 2008
  10. Jay SoffianJan 7, 2008
  11. David BrownJan 7, 2008

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.