Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you rename a folder in git and hide it with an interactive rebase?

Tags:

git

git-rebase

I have a project and during the course of the project I realized I don't like the name of a directory.

In GIT, we can rename the directory and then commit, but the history will still show the older folders.

I would like to rebase the name change as an earlier commit. So what I would normally do is:

git rebase -i origin/master

Then shift the folder rename commit to the top.
However, as expected git will yield a lot of conflicts that need to be resolved.

Is there a more automated way of doing this?

like image 943
Archimedes Trajano Avatar asked Mar 11 '13 22:03

Archimedes Trajano


1 Answers

If it is something you haven't shared with anyone yet, which I infer that it is since you are trying to rebase it anyway, I would remove the commit that contains the renaming, and do a filter-branch.

Assuming that foo contains the first occurrence of the bad directory, and your rename is the latest commit:

git reset --hard HEAD^ # removes the rename commit
git filter-branch --tree-filter "mv bad good" foo^..HEAD

This will rename the bad directory to good.

like image 81
magnus stahre Avatar answered Oct 03 '22 03:10

magnus stahre