简体   繁体   中英

Checkout all changed files from another branch within a certain directory

I hosed a branch with some unwanted merges and needed to push it to the remote and create a PR, but I had these superfluous commits from another branch which mucked up the diff between my branch and the base branch. What I needed to do was checkout all the changes within a single directory that I had been working on from the other branch. Thankfully my changes were isolated to a single directory.

What worked for me, which was kind of stated above but not explicitly:

I checked out a copy of the base branch I wanted to create the PR against:

git checkout <remote-branch>

If the branch name does not exist locally the remote branch will be checked out and created for you. You should be in this new branch now which is identical to the base branch you'll create a PR against.

At the root of your project, in your new branch you'll run:

git checkout <old-branch> ExampleDirectoryName/*

An example with multiple directories for clarity:

git checkout <old-branch> ExampleDirectoryName/ExampleDirectoryName2/*

This will checkout and stage every file that has changes that are not present in your current branch

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