emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Renaming files with git not all that bad?


From: Stefan Kangas
Subject: Re: Renaming files with git not all that bad?
Date: Thu, 9 Dec 2021 14:18:21 -0800

<tomas@tuxteam.de> writes:

> On Thu, Dec 09, 2021 at 03:55:34PM +0100, Stefan Kangas wrote:
>> Yuri Khan <yuri.v.khan@gmail.com> writes:
>>
>> > There is also a trick to split a file into multiple parts where each
>> > part retains its history.
>>
>> Thanks, I didn't know about this but will see if I can make it work
>> for the splitting up of image-dired.el.
>
> Based on [1], I once did:
>
>   #+file: ~/bin/gitlib
>   #+begin_src sh
>     #!/bin/bash
>     set -ex
>     # FIXME sanity checks missing!
>     # See git-sh-setup on some helpers for this
>     if [ $# -lt 2 -o $# -gt 3 ] ; then
>       echo "Usage: $0 orig copy [commit-message]"
>       exit 1
>     fi
>
>     orig="$1"
>     copy="$2"
>     message=${3:-"split off $copy from $orig"}
>
>     if [ -e "$copy" ] ; then
>       echo "$copy already exists: bailing out"
>       exit 1
>     fi
>     if [ ! -f "$orig" ] ; then
>       echo "$orig isn't an existing file: bailing out"
>       # FIXME might want to check that it /is/ a git file
>       exit 1
>     fi
>
>     echo "$message"
>
>     git mv "$orig" "$copy"
>     git commit -nm "$message"
>     REV=$(git rev-parse HEAD)
>     git reset --hard HEAD^
>     TMP=$(mktemp tmp-XXXXXX)
>     # note that $TMP exists after the mktemp, thus -f
>     git mv -f "$orig" "$TMP"
>     git commit -nm "$message"
>     # this fails because of conflicts: expected
>     git merge "$REV" || true
>     git commit -anm "$message"
>     git mv "$TMP" "$orig"
>     git commit -nm "$message"
>   #+end_src

Cool!

I'm not sure about this method, as it seems safer to use a named branch
instead of referring to some SHA1 directly.  Maybe that won't make any
difference to git though?

It's been over a decade since I last looked into how git stores data in
any detail, but IIRC a branch name is just a pointer to some SHA1 hash
recorded in a text file.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]