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

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

From
Jeff King <peff@peff.net>
Date
Jan 6, 2008, 08:08 UTC
Message-ID
<20080106080825.GA9718@coredump.intra.peff.net>
In-Reply-To
<379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com>
On Sun, Jan 06, 2008 at 03:55:22PM +0800, Jon Hancock wrote:
> So, do I need to use git's mv and rm commands?  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?

No, you don't need to use those commands. They really are just wrappers that manipulate the working tree files and the index at the same time. So instead of "git-mv a b" you can do "mv a b; git rm a; git add b".

Show 5 quoted lines
> 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?

"git add ." will add the contents of any modified files to the index, as well as add any untracked files (which may or may not be what you want). It will not add removals. Try "git add -u" which updates all files that git knows about (i.e., modifications and removals). You can also simply use "git commit -a" which is the moral equivalent of "git add -u ; git commit".

-Peff
Previous: Brian SwetlandNext: Linus Torvalds
Message 4 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.