IMPORTANT: The SHA must be "part" of the branch and it must be the first commit you want to delete. git log -oneline -graph presents commit history in a ASCII graph displaying the different branches in the repository and their commits. (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. That should show no changes (since only the history changed not the content of your files). Is it possible to show git history in the sidebar for previously committed changes Once I commit, it goes away: I can always git reset -soft HEAD and un-stage to get to: but then I have to either force push or force reset to sync with origin. 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 Git rebase -onto temp master # now rebase the part of history from to master onthe temp branch 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 |