Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git moving file while keeping history

Tags:

git

we are using git at work. we want to move a directory called "Workflows" from under Source/Workflows

to a new location Source/Sites/CompanySite/Workflows

my colleague did a copy of that directory to the new location "Source/Sites/CompanySite/Workflows" and checked-in before doing a "git mv" command or even doing a move.

So, we have new copies of the files in that location with no history.

But because we want to just move files keeping their history, so I deleted the new copy and tried to do "git mv" to move the source files, while keeping the history. And I know that git will recognize that we are renaming even without "git mv"

But because my colleague copy has already a history there (which is an empty one), so even when I delete it it keep that "new history".

Then no matter what I do, I am not able to move those files with their "original history".

because it always keeping the "new history" that was there.

I hope my question is clear

How can I move these files keeping their history. maybe "purging" that old copy????

like image 736
Ghassan Karwchan Avatar asked Dec 15 '25 13:12

Ghassan Karwchan


1 Answers

git mv doesn't actually ensure that Git will see it as a move; it may still treat it as a delete + addition, anyway. Git infers moves, but doesn't record them.

If you want the history, try passing the --follow flag to git log—it may be able to recognize the connection to the original and show the history for it.

like image 63
mipadi Avatar answered Dec 17 '25 09:12

mipadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!