Is it possible to remove all my commits and maintain only the last one
I have tried to follow some suggestions found here in other similar topics, trying to rebase my commits:
git rebase --onto master~5 master~1 master
but I don’t obtain what I would like (but it is possibly due to my inability).
Now, what I want is to remove all my commits and maintains only the last version of the file, like if I delete my file and I post it again for the first time.
I would like to remove commits on some gists; really I am interested only in the last version.
Really, I would like to use gist like pastebin, without saving revision but only maintaining the final one version.
I know that I could delete my gist and create another one, but, if possible, I prefer if the link not change.
One Solution collect form web for “Is it possible to remove all my commits and maintain only the last one”
If you are trying to discard all previous history for only a single file and that file is used in commits that modify other files,
rebase is (probably) necessary. If you just want to discard all history for the entire repository, here are two options:
Set HEAD to a new parentless commit with the current working dir as its tree (git checkout has an –orphan option that does something similar):
$ TREE=$( git show -s --format='%T' HEAD ) $ HEAD=$( echo initial commit | git commit-tree $TREE ) $ git reset $HEAD
After you’ve done this, all the previous commits are still accessible as objects, but you have to work to get them. If you have branches and/or tags that refer to them, they will persist, but if they are unreferenced they will eventually be discarded by the garbage collector.
or, just blow away the git repo and start over:
$ cd $( git rev-parse --show-cdup ) # Go to top level directory $ rm -rf .git $ git init $ git add .