How to merge/pull from remote repository
I'm trying to merge a few subdirectories from a remote git repository to my repository. Both Remote and Local Repositories include the whole kernel repository and I'm interested only in the wireless relevant files.
I tried to follow the instructions under "How to use the subtree merge strategy", but since most of the files exist both in local repository and in remote repository the
git read-tree --prefix=dir-B/ -u Bproject/master
command fails. I could not use -m
option and --prefix
in the same command line.
This merge actually should update (merge/pull) all relevant 开发者_如何转开发wireless directories/files according to the files in the remote repository where conflicts should be solve by preferring the remote files.
To make my question general -- say you have repository A and B. both have the folder wireless_dir: A/wireless_dir, B/wireless_dir. I'm working on repository B and would like to update all its files in B/wireless_dir from A/wireless_dir where changes in A/wireless_dir are preferred when merge conflicts occur.
From what Jeformi commented, it appears you already have the situation where the folder is a separate repository, which if that's the case all you have to do is a git pull
.
However, if the commits you're looking for have files from other folders that you don't want, Git allows you to "unsqaush" commits in a round about way as mentioned here: redhatmagazine
The steps to do this (a bit more generalized to your situation) are:
1) Make note of the commit your HEAD is currently at, let's call it <OLD_HEAD>
for fun. This can be obtained from the log and looking at the most recent commit's sha1 by using:
git log
2) Pull in the changes from repo A into your branch (this will include any that you might not want):
git pull <repo A> <branch_name>
3) Now's it's time to use <OLD_HEAD>
(in a non-vulgar way)... this is done by a reset
git reset --mixed <OLD_HEAD>
4) With everything you've done you're HEAD is back at <OLD_HEAD>
and your index is as well, but in your working directory you now have the changes from repo A that you've been looking for, as well as the potential for files outside of the wireless_dir folder. To interactively merge these files in your working directory into your index use (only on the files from wireless_dir if that's all you want):
git add --patch <filename>
5) And finally:
git commit -m “Selectively merged my files”
Note: If you don't want to chance screwing up your branch, make a new branch before trying the above.
The easiest way to do it is to merge the entire branch, copy that folder outside of your git tree, undo or abort the merge, then copy the folder back in.
However, you're going to have problems if any of the changes have dependencies outside that folder. You probably want to cherry-pick
the entire commits of anything that touches that folder (from git log subdir
) to pull in the dependencies.
精彩评论