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: Yuri Khan
Subject: Re: Renaming files with git not all that bad?
Date: Sat, 11 Dec 2021 19:11:14 +0700

On Fri, 10 Dec 2021 at 05:03, Stefan Kangas <stefan@marxist.se> wrote:

> >> Couldn't the same effect be achieved in a simpler manner by copying the
> >> original file N times in one commit and then stripping the copies and
> >> original down to what they should eventually become?  (AFAIK, git has no
> >> problem detecting literal copies.)
> >
> > Indeed, I tried this and it works for me, as long as the first commit
> > is only literal copies. Maybe Git’s ancestry detection through copies
> > was not as advanced in the unspecified times when Raymond invented his
> > technique.
>
> I'm having no luck with this.
>
> Could you describe the exact steps you took?

I start with the same steps described in Raymond Chen’s article:

git init

>foods echo apple
>>foods echo celery
>>foods echo cheese
git add foods
git commit --author="Alice <alice>" -m created

>>foods echo eggs
>>foods echo grape
>>foods echo lettuce
git commit --author="Bob <bob>"   -am middle

>>foods echo milk
>>foods echo orange
>>foods echo peas
git commit --author="Carol <carol>" -am last

git tag ready


Next:

cp foods dairy
cp foods fruits
git mv foods veggies
git add dairy fruits
git commit --author="Donald <donald>" -m "split part 1"

sed -rni '/^a|^g|^o/p' fruits
sed -rni '/^ce|^l|^p/p' veggies
sed -rni '/^ch|^e|^m/p' dairy
git commit --author="Donald <donald>" -am "split part 2"

At this point, the line history in each file is preserved:

git blame dairy
^2221a21 foods (Alice 2021-12-09 13:27:21 +0700 1) cheese
d12be427 foods (Bob   2021-12-09 13:27:27 +0700 2) eggs
ada8f5c5 foods (Carol 2021-12-09 13:27:31 +0700 3) milk

git blame fruits
^2221a21 foods (Alice 2021-12-09 13:27:21 +0700 1) apple
d12be427 foods (Bob   2021-12-09 13:27:27 +0700 2) grape
ada8f5c5 foods (Carol 2021-12-09 13:27:31 +0700 3) orange

git blame veggies
^2221a21 foods (Alice 2021-12-09 13:27:21 +0700 1) celery
d12be427 foods (Bob   2021-12-09 13:27:27 +0700 2) lettuce
ada8f5c5 foods (Carol 2021-12-09 13:27:31 +0700 3) peas

‘git log’, however, does not trace file history beyond the split by default:

git log --oneline dairy
8d6d788 (HEAD -> master) split part 2
4be5ed0 split part 1

It does if you ask:

git log --oneline --follow veggies
8d6d788 (HEAD -> master) split part 2
4be5ed0 split part 1
ada8f5c (tag: ready, split-via-rename) last
d12be42 middle
2221a21 created


Doing it Raymond’s way (via multiple branches with a single rename and
paring down on each branch, then octopus-merging the branches)
produces the same effects: blame assigned correctly, file-filtered log
complete only on --follow.



reply via email to

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