I am in a situation where I am trying to convert an open source project to Git, and I have recently gained access to historical data for the project. I have already made modifications to the repo, though, so I want to add these early changes as git commits to the beginning of the tree of commits in Git. (Yes, I am aware that this will change the SHAs for later commits; this is acceptable.) The data is provided as successive snapshots of the working directory. I want to set it up so that the state of the working directory for the later commits is not affected (I don't want to merge the changes in).

For example, if initial commit B adds files a and b to the working directory, and my historical commit A adds file a, I want to make a new commit B' parented from A that adds file b only. In both B and B', the working directory looks the same, and any subsequent commits on top of B can be safely rebased onto B'.

Is it possible to do this in Git? If so, how?

Edit: Note that I need to modify the initial commit. The standard usage of git commit appends a new commit as a child of the HEAD commit, and so does not work for the initial commit, which has no parent.


Something like this should work.

# Create a new branch with the old history
$ git checkout --orphan old-history    
$ git add <old-files>
$ git commit

# Rebase master on top of the branch with old-history
$ git checkout master
$ git pull --rebase . old-history

Im not sure if its possible to just do:

git add [files]
git commit -m 'first commit'

Then merge changes

git add [files]
git commit -m 'second commit'


git push

If this doesnt work then i think there is no way of achieving that.

  • 1
    Of course you can do this, but it will add the old commits to the end of the tree, not the start. – Mario Carneiro Aug 3 '13 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.