How can I transfer the commit history of a repository to another repository?

时间:2015-10-30 22:51:06

标签: git repository commit git-commit

I've spent a few months working on a project. It broke, I started a new project and just transfered the files, but I would like to transfer just the commit history into the new repository/project? I am a little familiar with git. What command line codes would I need to only transfer the commit history?

2 个答案:

答案 0 :(得分:2)

Basically you want to add a new remote, so in the old project you just need to add a new remote:

$ git remote add origin git@remote-path/project.git

then run:

$ git remote -v

and you should have two remotes.

If you have the error:

fatal: remote origin already exists.

just use other name for remote:

$ git remote add new-origin git@remote-path/project.git

答案 1 :(得分:1)

Figured it out. Simply:

  1. Go to project directory

    cd ProjectAcceptingCommitMessages
    
  2. Add project with commit history to current repository

    git remote add projectB /home/you/projectB
    git fetch projectB
    
  3. Then merge the two together, therefore giving you the commit history

    git merge projectB/master