In Git, how do I create a commit that's before the oldest commit?

I have a Git repository whose oldest commit is version 6.8.2 (it is tagged “v6.8.2”). I have version 6.8.1 of the package that I would like to commit to the repository as the parent commit of the oldest commit. Is this possible? If so, how?

  • NetBeans + FTP + BitBucket
  • How to undo git pull from unrelated project?
  • Can I enforce a merge-only branch in git?
  • Changing url of Git submodule fails
  • How can I delete a git branch after using `git merge --squash`
  • Git Bash Slow on Windows 10
  • in git, what is best way to keep snapshots of different versions?
  • How to show current Git branch in an Android application programatically?
  • can't deploy git repository to dokku instance (fatal: {reponame} does not appear to be a git repository)
  • How to get Git Merged Date Revision Log history?
  • Setting up a git repository on a openSuse VPS
  • Having trouble with .github.io
  • One Solution collect form web for “In Git, how do I create a commit that's before the oldest commit?”

    You could rebase your current branch on top of the oldest commit that you want (v6.8.1). It will rewrite your history, though, but it is possible.

    Edited to add more

    Assuming your code is on the branch master

    Clear out the existing code and create a new branch. Your old code is not lost – it still exists on the master branch.

    git symbolic-ref HEAD refs/heads/newbase
    rm .git/index
    git clean -dxf
    

    Now you are on the branch newbase which is an empty directory. Add the files that you want to be the new base to here.

    <add the files to the directory>
    git add .
    git commit -a -m "New base commit v6.8.1"
    

    New you have two branches master which has your original code and newbase which has only your new base.

    Now checkout the master branch and rebase it upon the newbase branch

    git checkout master
    git rebase newbase
    

    And then All you need to do is fix the conflicts, and you have a new master branch that starts at the earlier state of the code.

    This is all a bit of a mess though. If you just want to add the code to the repository, just do the first bit, which creates a new branch. Tag it so that you know what it is, there is no need to rebase the master branch on to it because if you get to the base of master, and want to go further back in time – you can just see what is in the other branch.

    Git Baby is a git and github fan, let's start git clone.