Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: how to remove history before a specific commit

I.e., I have:

root -- c1 -- c2 -- .. - c1000 -- c1001 -- c1002 -- .. -- c2000 -- top

and I want to have:

root = c1000 -- c1001 -- c1002 -- .. -- c2000 -- top

How?

(I guess I can do via git filter-branch, but how exactly?)

(Of course I know that this means history-rewriting...)

like image 254
Albert Avatar asked Sep 18 '11 02:09

Albert


People also ask

Can we remove git commit history?

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history.

How do you remove all commits before a commit?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.


1 Answers

I have found the below useful for creating new repos with a different root ( which is what I think you are asking when you say remove history before a commit):

git fast-export master~5..master | (cd ../newrepo.git && git init . && git fast-import && git checkout)

(you can do the above in the same repo too)

like image 109
manojlds Avatar answered Sep 28 '22 23:09

manojlds