简体   繁体   中英

Fork particular files from a repository in github

i'd like to fork only a couple of files from some repository. For these particular files I'd like to be able to track and merge the upstream changes.

Best Regards

This should work, although it's clunky (and I haven't tested it):

$ git fetch upstream
$ git diff upstream/master -- file1.ext path/to/file2.ext yet/another/file3.ext | git apply -
$ git add file1.ext path/to/file2.ext yet/another/file3.ext
$ git commit

Where "upstream" is the name of the upstream remote, and "master" (as in "upstream/master") is the branch you're tracking.

Basically, you're saying "fetch the latest changes from upstream, make a patch of what's different between my current files and the upstream files, for a certain list of files, apply that patch, add the files to the index, and commit".

(The working tree should be clean, or else you'll be including changes not from upstream in your commit, which is not a problem but can be confusing.)

Look at sub-modules. You may find after digging into it that the complexity isn't warranted. It's likely better to just clone the entire repository and ignore the other files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM