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

Re: "git rm" is not a valid merge resolution?

From
Piotr Krukowiecki <piotr.krukowiecki@gmail.com>
Date
Mar 21, 2011, 19:56 UTC
Message-ID
<4D87AD79.5000806@gmail.com>
In-Reply-To
<vpqpqpk724l.fsf@bauges.imag.fr>
W dniu 21.03.2011 19:35, Matthieu Moy pisze:
Show 13 quoted lines
> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
> 
>> Hi,
>>
>> git-status shows a hint that says
>>     use "git add/rm <file>..." as appropriate to mark resolution
>>  
>> But if I "git rm file" the file gets deleted. Is this really the 
>> appropriate merge resolution?
> 
> In most cases, no, but when you have a modify/delete conflict for
> example, "git rm" is one of the candidates to resolve the conflict. The
> hint gives the general case.

I think this is not completely true. You can stage removal of a file with git add, but it's harder than use of git rm.

This is something I don't understand. Why is there a difference between removing files and (adding files or removing content)?

You must use special flags to "git add" to remove files, while you don't need such flags to add file or remove content.

All changes are tracked. You won't loose your data if you remove the file by mistake. It is the same as remove some content by mistake.

Is it caused by the name of the command ("add")? Some people would be surprised if "git add" marked removed file for removal. But I think some would be already surprised that you have to "add" your changes.

Or maybe it is caused by the fact that "git tracks content" (if I remember correctly)? I don't see a problem here. The command just tells git what content it should track. "git add" does not say "track this change (file path addition/file deletion)" but "track this file path content", so if the file got deleted there is nothing to track.

Maybe the command should be named "stage". You should stage your changes. Add the file deletion is the same change as file addition.

You would do
   
    git stage addedfile
    git stage deletedfile
    git stage changedfile
This would be consistent.

(For me it doesn't need to be "stage" name. It could be handled by "add").

Currently it works like this:
   git add untracked # Adds untracked file 
   git add . # Adds all untracked files
   rm tracked
   git add tracked # Does not stage the delete
   git add . # Does not stage the delete
   git add -A tracked # This works - stages deletion of tracked file
   git add -u # Stages all tracked changes, also new/deleted tracked files
   git add -A # Stages all changes, also new/deleted untracked files
   # No way to do following (without listing files explicitly):
   # 1. Added several new files, but has also several tracked files changed
   #    and want to only add new files
   # 2. Removed several tracked files, but has also several other tracked
   #    files changed and want to only remove deleted files. 
-- 
Piotr Krukowiecki
Previous: Matthieu MoyNext: Junio C Hamano
Message 3 of 6 in “"git rm" is not a valid merge resolution?”
  1. Piotr KrukowieckiMar 21, 2011
  2. Matthieu MoyMar 21, 2011
  3. Piotr KrukowieckiMar 21, 2011
  4. Junio C HamanoMar 21, 2011
  5. Piotr KrukowieckiMar 21, 2011
  6. Junio C HamanoMar 21, 2011

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.