wchargin
wchargin

Reputation: 16037

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?

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 master) and that I haven't touched master since I branched out.

I've also read this question.

What's the best way to do this?

Upvotes: 5

Views: 2193

Answers (3)

Max
Max

Reputation: 1068

https://git-scm.com/docs/git-filter-branch states:

To move the whole tree into a subdirectory, or remove it from there:

git filter-branch --index-filter \
    'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
     mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

Upvotes: 2

z0r
z0r

Reputation: 8585

git filter-branch should work fine; just make the mv command fail gracefully by appending || true. For example, to rename baz/ to foo/bar/baz/:

git filter-branch --force --tree-filter \
    'mkdir -p foo/bar; mv baz foo/bar/ || true' \
    --tag-name-filter cat -- --all

Upvotes: 5

Philip Oakley
Philip Oakley

Reputation: 14061

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.

Upvotes: 0

Related Questions