From: Erik Cervin Edin <erik@cervined.in>
To: rsbecker@nexbridge.com
Cc: Jeremy Morton <admin@game-point.net>, git@vger.kernel.org
Subject: Re: Proposal: tell git a file has been renamed
Date: Sun, 23 Apr 2023 11:38:52 +0200 [thread overview]
Message-ID: <CA+JQ7M8avZiZuBHUtkQu2WqtR4zozU3C2ayCjBxRsQcKjAr16g@mail.gmail.com> (raw)
In-Reply-To: <01d301d97567$0e9bc0b0$2bd34210$@nexbridge.com>
On Sat, Apr 22, 2023 at 9:57 PM Jeremy Morton <admin@game-point.net> wrote:
>
> https://stackoverflow.com/a/1094392/178757
>
> says:
>
> git mv oldname newname
>
> is just shorthand for:
>
> mv oldname newname
> git add newname
> git rm oldname
That's what I though but it's more like:
git show :0:oldname > newname
git add newname
git rm --cached oldname
mv oldname newname
Basically, a move but also preserving staged/unstaged contents. But
yes. How git handles renames can sometimes be a bit of a PITA.
On Sun, Apr 23, 2023, 12:16 AM <rsbecker@nexbridge.com> wrote:
>
> $ git add file1
> $ commit -m "Commit 1"
> $ git mv file1 file2
> $ git status
> On branch master
> Changes to be committed:
> (use "git restore --staged <file>..." to unstage)
> renamed: file1 -> file2
I think your point is better illustrated
git add file1
commit -m "Commit 1"
echo 'Changed' > file1
git mv file1 file2
git status
Which yields:
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: file1 -> file2
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file2
Or perhaps even:
echo Initial > file1
seq 1 10 >> file1 # We need a larger file to detect rename with change
git add file1
git commit -m 'Commit 1'
seq -i 's/Initial/Changed/' file1
git add file1 # Stage changes
seq 11 20 >> file1 # Add some unstaged changes
git mv file1 file2
This will result in a staged rename, as well as the staged change
'Initial' -> 'Changed' with a bunch of additional unstaged lines of
numbers 11 to 20.
NB that this doesn't play nice unless the contents of file1 in HEAD
and index are similar enough (at least 50%?)
next prev parent reply other threads:[~2023-04-23 9:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-22 18:01 Proposal: tell git a file has been renamed Jeremy Morton
2023-04-22 18:54 ` rsbecker
2023-04-22 19:44 ` Jeremy Morton
2023-04-22 19:47 ` rsbecker
2023-04-22 19:54 ` Jeremy Morton
2023-04-22 22:09 ` rsbecker
2023-04-23 9:38 ` Erik Cervin Edin [this message]
2023-04-23 21:01 ` Kristoffer Haugsbakk
2023-04-24 1:43 ` Chris Torek
2023-04-24 10:10 ` Jeremy Morton
2023-04-24 10:24 ` Chris Torek
2023-04-24 10:49 ` Erik Cervin Edin
2023-04-24 11:17 ` Jeremy Morton
2023-04-24 14:00 ` Erik Cervin Edin
2023-04-24 14:42 ` Jeremy Morton
2023-04-24 19:25 ` Felipe Contreras
2023-04-24 19:44 ` Jacob Keller
2023-04-24 20:00 ` Felipe Contreras
2023-04-26 19:08 ` Jacob Keller
2023-04-26 20:39 ` Junio C Hamano
2023-05-11 13:44 ` Erik Cervin Edin
2023-04-24 18:26 ` Junio C Hamano
2023-04-24 19:41 ` Junio C Hamano
2023-04-24 20:05 ` Jeremy Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+JQ7M8avZiZuBHUtkQu2WqtR4zozU3C2ayCjBxRsQcKjAr16g@mail.gmail.com \
--to=erik@cervined.in \
--cc=admin@game-point.net \
--cc=git@vger.kernel.org \
--cc=rsbecker@nexbridge.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).