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).

  • GIT core.editor setup on windows along w application PATH reference
  • Can run update and it works, but commit says illegal repository url ''?
  • Golang: Executing a command with it's arguments
  • SVN: Force svn daemon to run under different user
  • How do you commit code as a different user?
  • How to avoid .git files when comparing two folders
  • 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.

  • What's the difference “origin master” vs “origin/master”
  • Do different versions of a file get their own blob/sha?
  • Is there a way to “freeze” a file in Git?
  • Git: massive refactor keeping changes log
  • Why doesn't my git info show up in my prompt unless I reload my .zshrc?
  • Git - Can't push to local bare repo on Windows
  • 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 .
    
    Git Baby is a git and github fan, let's start git clone.