wchargin wchargin - 1 year ago 119
Git Question

Rename directory throughout Git commit history

I'm trying to rename a directory that was introduced six commits ago and in all subsequent commits. These commits have not been pushed.

What have I tried?

  • I've tried using
    git filter-branch
    with an
    mv old new
    command, but this fails on commits before
    because the directory doesn't exist.

  • I've tried
    git rebase -i HEAD~6
    , editing each commit, but I can't use
    mv old new
    because git's locking the file, nor can I rename it in Windows Explorer.

  • I've tried the same rebase with
    cp -R old new; rm -rf old; git add new
    but this creates merge conflicts on
    and above.

It may be worth noting that the commit on which this directory was introduced is the first commit in this branch (the branch is six commits ahead of
) and that I haven't touched
since I branched out.

I've also read this question.

What's the best way to do this?

Answer Source

Why not simply start a new branch (at master) and then do a simple swap between the old and the new branches at ~N and pick off the 6 commits in a row.

For example git cherry-pick & git mv old new & git commit.

It may not be 'fast' but it would be quick enough with only 6 commits to fix.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download