当前位置: 动力学知识库 > 问答 > 编程问答 >

How to merge codeline with git

问题描述:

I have a codeline with certain change number A. I git init on it and I edit some files and then add p4 opened files by git add and then git commit to my local repository.

There's another guy working on the SAME codeline with different change number B. He also edited some files, some of which are common files between us and he also did the git init, git add and git commit to his local repository.

We don't have a central global repo in the first place. But now I want to merge his git changes into my client. How can this be done via git?

myGitCodeLine------?

hisGitCodeline------/

网友答案:

First you need some kind of access to his repo. A simple shared directory is enough. Other options are detailed here.

Then you need to clone his repo (B) in order to get all the changes. You can make a branch in your own repo A, and git add everything checked out by the second repo B.
A trick to do that easily is to:

  • make a second root branch in your repo (in order to start from an empty content)
    git checkout --orphan branchForB: see this SO answer as an example.
  • use --work-tree=<path> option to git to add files from other directory:
    git --work-tree=/path/to/file add ., as mentioned in "How can I create a new branch in git from an existing file tree?"

Once that is done:

  • you can merge that second branch into your main branch.
  • you need to ask B to clone your repo A in order for you both to work from a common history.
分享给朋友:
您可能感兴趣的文章:
随机阅读: