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?

  • How to view git log in Emacs?
  • Git diff --stat explanation
  • Creating a New Git Repo from existing files on Windows
  • Collaboration
  • Perforce for Git users?
  • How to commit no change and new message?
  • Interactive rebase for only my commits
  • How to set up a git development environment when you're testing remotely
  • Convert a Git working directory to a bare-like repository?
  • Can one git repository track subversion and git remotes?
  • Cloning a Git repo without the .git directory
  • automated code formatting git
  • 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.