3

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????

Ghassan Karwchan
  • 3,355
  • 7
  • 37
  • 65
  • 1
    How far back in the history did your co-worker do this and how big is the team (IE, how practical is rebasing to throw away your co-worker's commit and try again)? – Roman Jun 10 '14 at 19:04
  • I recommend the solution posted in http://stackoverflow.com/a/13590229/1579915. – dr0i Jan 25 '16 at 14:43

2 Answers2

1

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.

mipadi
  • 398,885
  • 90
  • 523
  • 479
1

it depends on your requirements: there is a possibility to use git-filter-branch

this allows you to apply a shellscript on every commit like: git filter-branch --tree-filter 'rm filename' HEAD

be aware though that it will create new commit-ids for each commit. See also this SO Question on moving files with filter-tree.

Community
  • 1
  • 1
Alexander Oh
  • 24,223
  • 14
  • 73
  • 76