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

Proposed git mv behavioral change

From
Llmage11@twcny.rr.com <lmage11@twcny.rr.com>
Date
Oct 18, 2007, 15:47 UTC
Message-ID
<c594999b2337.2337c594999b@nyroc.rr.com>
Hey, all...

Based on a question I asked on freenode's #git channel a few days ago, it seems that most people only use git mv when the file they're moving is clean. Those that don't have become accustomed to the behavior that git-mv uses when the file is dirty - to pull all unstaged changes into the index. As far as I can tell, this behavior is largely historical. When git-mv was written in bash (or perl, or whatever it was initially written in), it was most convenient to implement it as "mv oldname newname; git add newname;", or something similar, which would result in pulling in all wd changes. However, it seems to me that this behavior violates git's consistency. Usually when I do something with git, I expect it to do only what it says it will do, and nothing more. The documentation for git-mv says "The index is updated after successful completion", but I would tend to assume that this was referring to the name change and not the change in the actual contents of the file.

In my situation, I have some changes to a file that I'm not yet ready to commit. In the meantime, I've started working on another unrelated change that involves renaming one of the files which contain unstaged changes. I'd like to be able to perform this move without having my unstaged changes implicitly staged without my knowledge. When I want information put into the index, I either use git update-index if I want to explicitly stage an entire file or I use git add -i's patch command to explicitly stage individual chunks. I like having very fine-grained control over what goes into the index and what doesn't.

Therefore, I propose that git mv's behavior be changed. I think it would make far more sense for a move to only change the actual name of the file and to not pull in unstaged changes. In other words, I'd like the index entry for the original file name to be removed and an index entry to be added with a different name, but using the exact same blob hash as the original file. I don't know exactly how git manages the index internally, but a shortcut for this would be to simply rename the index entry in place.

I'm willing to look into what changes would need to be made to the code for this change to happen; I'm not asking for someone to do all the work for me. :)

So... Yeah. I'd like to know what people think about this before I put a significant amount of effort into it. After all, we know how lazy programmers are... :)

Thanks,
   Ari
Next: Michael Witten
Message 1 of 34 in “Proposed git mv behavioral change”
  1. lmage11@twcny.rr.comOct 18, 2007
  2. Michael WittenOct 19, 2007
  3. Shawn O. PearceOct 19, 2007
  4. Michael WittenOct 19, 2007
  5. Shawn O. PearceOct 19, 2007
  6. Jeff KingOct 19, 2007
  7. Michael WittenOct 19, 2007
  8. Wincent ColaiutaOct 19, 2007
  9. Michael WittenOct 19, 2007
  10. Shawn O. PearceOct 19, 2007
  11. Michael WittenOct 19, 2007
  12. Shawn O. PearceOct 19, 2007
  13. Jeff KingOct 19, 2007
  14. Michael WittenOct 19, 2007
  15. Jeff KingOct 19, 2007
  16. Michael WittenOct 19, 2007
  17. Jeff KingOct 19, 2007
  18. Michael WittenOct 19, 2007
  19. Jeff KingOct 19, 2007
  20. Ari EntlichOct 20, 2007
  21. Jeff KingOct 20, 2007
  22. Michael WittenOct 20, 2007
  23. Jeff KingOct 20, 2007
  24. Shawn O. PearceOct 20, 2007
  25. Jeff KingOct 20, 2007
  26. Karl HasselströmOct 22, 2007
  27. Michael WittenOct 20, 2007
  28. Shawn O. PearceOct 20, 2007
  29. Wincent ColaiutaOct 20, 2007
  30. Karl HasselströmOct 22, 2007
  31. Ari EntlichOct 20, 2007
  32. Shawn O. PearceOct 20, 2007
  33. Mike HommeyOct 20, 2007
  34. Jeff KingOct 20, 2007

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.