简体   繁体   English

从某个目录中的另一个分支检出所有更改的文件

[英]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.我用一些不需要的合并处理了一个分支,需要将它推送到远程并创建一个 PR,但是我从另一个分支收到了这些多余的提交,这弄乱了我的分支和基本分支之间的差异。 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:我检查了我想针对其创建 PR 的基本分支的副本:

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.您现在应该在这个新分支中,它与您将针对其创建 PR 的基本分支相同。

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这将检出并暂存具有当前分支中不存在的更改的每个文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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