Josh
Josh

Reputation: 13

Moving root of git repo down one level in folder hierarchy while preserving history

So I have a git repo in this structure:

app
    app_one
    app_two
    app_three

The git repo root is in app. What I want is the root to simply be a folder containing app_one, app_two, app_three.

app_one
app_two
app_three

But the caveat is I want to do this while maintaining the current history of the file. Aka when I push this change to github, I don't want everything to show it was updated 3 seconds ago.

Upvotes: 1

Views: 749

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83517

I want to do this while maintaining the current history of the file.

The easiest (and best IMO) way:

git mv app_one app_two app_three .
git commit

You will still have access to the entire history of changes for all files in every folder.

I don't want everything to show it was updated 3 seconds ago.

This would require entirely rewriting the commit history with git filter-branch or git rebase. These are both dangerous if there are other developers who are working on existing branches. Also, they take a lot more time and effort. The above solution will work just fine for more cases.

For information about viewing history information across file moves see this question.

Upvotes: 4

Related Questions