简体   繁体   中英

Merging/Copying Specific files to master from Branch

I run following command to find file names that were changes in branch but NOT in master:

git diff --name-status master..branchName

It gives a list of file names with full path.

Now I have cloned master on local machine and want to copy, those changed files in master. I said copy as I don't want to merge and run into conflicts.

Is there a way to get some kind of patch which have files in relevant folders? instead of manually copying them?

You can just redirect output of the git diff command to a file.

$ git diff master..branchName -- the/relevant/path1 the/relevant/path2 ... > my.patch

Then use git apply my.patch to apply the changes all at once.

Another option is to checkout the files/directories that you want:

$ git checkout master
$ git chechout branchName -- the/relevant/path1 the/relevant/path2 ...

What you want is to have the working directory and index of your branch and your repository pointing to master commit.

The way to do that is with git-reset :

git checkout yourBranch
git branch tempBranch   // It is allways safer create a temporal branch when you play with git-reset
git reset --soft master // This moves to master commit but does not touch your working directory and index area.

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