4

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?

Steve Emmerson
  • 7,342
  • 5
  • 31
  • 57
  • Hakre, no. The repository is private and has no clones. – Steve Emmerson Jun 16 '11 at 22:01
  • You could take back the 6.8.2 commit, make your 6.8.1 commit, then do your 6.8.2 commit on top of it and done - just rewriting the history. As you haven't pushed yet no problem. – hakre Jun 16 '11 at 22:22
  • 2
    possible duplicate of [git: how to insert a commit as the first, shifting all the others?](http://stackoverflow.com/questions/645450/git-how-to-insert-a-commit-as-the-first-shifting-all-the-others) – Josh Lee Jun 17 '11 at 02:04

1 Answers1

4

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.

Abizern
  • 129,329
  • 36
  • 198
  • 252
  • I don't see how because the repository doesn't contain a commit of version 6.8.1. My question is how to get a commit of that version into the repository and then how to make it the parent of the initial commit. – Steve Emmerson Jun 16 '11 at 22:00
  • @Steve Emmerson - Updated now. – Abizern Jun 16 '11 at 23:21