Merge two git repositories of same project

前端 未结 2 1241
谎友^
谎友^ 2021-01-05 05:48

I am currently the only developer working on a project I took over from my predecessor. When I took over the project, it was not under source control. So I created a new git

2条回答
  •  执念已碎
    2021-01-05 06:51

    Sure, using the ours strategy!

    Follow the the next steps (lines starting with # are comments):

    # Navigate to your updated project
    cd your-updated-project
    
    # Add a remote pointing to the other git repository 
    # (it can be a local path or an url; I used a local path)
    git remote add old-project ../path/to/the/old/git/repo
    
    # Get the content from that repo
    git fetch old-project
    
    # Merge the the old repo master branch in your current branch,
    # BUT keeping your recent changes (see -s ours)
    git merge old-project master -s ours
    

    If you want to merge another branch from the old git repo, do git merge old-project -s ours (replace with the branch name you want to merge).

提交回复
热议问题