![]() ![]() IMPORTANT: The SHA must be "part" of the branch and it must be the first commit you want to delete. (Push force, if any remote is present.). ![]() Go down history and find the first (newest) commit SHA you want to cut off (assume it's 2c75a32) AND ensure the commit has no branches in parallel!.Check out the branch you'd like to truncate (maybe master).Save the script above to local repository root (maybe as git-truncate.sh).Git for-each-ref -format='%(refname)' refs/original | \ Git gc -aggressive # aggressively collect garbage may take a lot of time on large reposįor those who get alot of merge conflicts (and broken results) with rebase -onto I'd like recommend this script which uses git filter-branch: #!/bin/sh git prune -progress # delete all the objects w/o references The following 2 commands are optional - they keep your git repo in good shape. Can I grep in the content (not in the commit messages) A very poor solution is to grep the log: git log -p grep However, this doesn't return the commit hash straight away.That should show no changes (since only the history changed not the content of your files). Asked 13 years ago Modified 6 months ago Viewed 587k times 1860 I have deleted a file or some code in a file sometime in the past. Warning this is a dangerous command don't use this lightly! If you want to be sure that your last version of the code is still the same you can run git diff origin/master. If you have a remote where you want to have the same truncated history you can use git push -f. ![]() Git branch -D temp # we don't need the temp branch anymore When you have just found out that you or a fellow team mate has. Git rebase -onto temp master # now rebase the part of history from to master onthe temp branch Deleting your git commit history without removing repo on Github/Bitbucket. Git commit -m "new root commit" # create a new commit that is to be the new root commit Here we go: ( is the sha of the commit f that you want to be the new root commit) git checkout -orphan temp # checkout to the status of the git repo at commit f creating a branch named "temp" In order not to lose some history better first take a copy of your repository :). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |