Git merge single file from another repository into my own

后端 未结 4 731
耶瑟儿~
耶瑟儿~ 2020-12-31 13:08

Say I have my own git repo with a bunch of text files in it. There is another different git repo that someone else owns with a bunch of text files that all differ from my ow

相关标签:
4条回答
  • 2020-12-31 13:40

    You can merge arbitrary files or repo objects. Simplest might be:

    git merge-file file.txt <(git show last-merged-file.txt) /path/to/their/file.txt
    # resolve any conflicts, then
    git tag last-merged-file.txt `git hash-object-w file.txt`
    
    0 讨论(0)
  • 2020-12-31 13:42

    Try to add the other-repo then bring its branches including your target-branch

    git remote add other git@github.com:username/other-repo.git
    git fetch other
    

    Switch to the branch you want to merge in the target-file.ext:

    git checkout your-branch
    

    Merge the target file into yours:

    git checkout -p other/target-branch target-file.ext
    
    0 讨论(0)
  • 2020-12-31 13:53

    Go to your current directory, This way I'm doing currently, I hope you will help too.

    cd your_current_git_Directory
    

    Set your username and repository of another repository/second(from want to copy)

    git remote add -f repo-b git@github.com:<username>/<repository>.git
    

    Now, Merge the filename you looking for(if you want file merge subfolder)

    git checkout -p repo-b/master  <folder_name>/<filename>
    

    Or merge filename only

    git checkout -p repo-b/master  <filename>
    

    And Remove repository

    git remote rm repo-b
    
    0 讨论(0)
  • 2020-12-31 13:56

    If you are using any kind of packaging (artifacts) results in the original repo, then you can ask the owner of the repo to publish the sources as well. Then in your own repo you consume and unpack such artifact and just copy the file you need. E.g. If using Java-Maven, make sure the build on the original repo publishes also the sources, then in your own repo, you put a pre-step (before compile) in which you download the sources dependency, unpack the jar file and copy the one you need to your proper directory. There are maven plugins for that

    0 讨论(0)
提交回复
热议问题