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

2
  • 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)? Commented Jun 10, 2014 at 19:04
  • I recommend the solution posted in stackoverflow.com/a/13590229/1579915. Commented Jan 25, 2016 at 14:43

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.