Cherry-pick特定文件夹中的提交部分从一个分支到另一个分支。

huangapple go评论58阅读模式
英文:

Cherry-pick section of commits from one branch to another, for specific folder

问题

I read few answers regard cherry-pick but couldn't found exactly what am I looking for.
我阅读了一些关于cherry-pick的答案,但没有找到确切的我所寻找的内容。

I work on a local branch of very large project.
我在一个非常大的项目的本地分支上工作。

My work is under a specific folder lets say LargProj/MyFolder.
我的工作在一个特定的文件夹下,比如说LargProj/MyFolder。

While Master branch is update each day in many places, I am working on my local branch and once in few weeks I want to takes all the new commit from master, to my branch.
虽然主分支每天在许多地方更新,但我在我的本地分支上工作,每隔几周我想将主分支上的所有新提交合并到我的分支。

When I use cherry-pick MasterCommitHashStart..MasterCommitHashEnd There are a lot of conflicts on files and folder I don't care about.
当我使用cherry-pick MasterCommitHashStart..MasterCommitHashEnd时,会出现很多与我不关心的文件和文件夹有关的冲突。

How can I cherry-pick only the changes relevant to MyFolder between MainHashStart..MainHashEnd?
我如何只选择与MyFolder相关的更改,介于MainHashStart和MainHashEnd之间?

Thanks a lot
非常感谢。

英文:

I read few answers regard cherry-pick but couldn't found exactly what am I looking for.
I work on a local branch of very large project.
My work is under a specific folder lets say LargProj/MyFolder.
While Master branch is update each day in many places, I am working on my local branch and once in few weeks I want to takes all the new commit from master, to my branch.

When I use cherry-pick MasterCommitHashStart..MasterCommitHashEnd There are a lot of conflicts on files and folder I don't care about.

How can I cherry-pick only the changes relevant to MyFolder between MainHashStart..MainHashEnd?

Thanks alot

答案1

得分: 3

> 如何仅挑选与 MainHashStart..MainHashEnd 之间的更改与 MyFolder 有关

你不能。Git 不涉及"更改"或"文件夹"。它涉及"提交"。提交基本上是项目工作树在某一时刻的完整快照。你唯一能挑选的是一个提交。

但你可以创建一个补丁,编辑它,然后应用编辑后的补丁。

或者(我会选择这样做)只需使用 git restore 从目标提交中提取特定个别文件的所需状态到工作树中,然后创建一个新的提交。

英文:

> How can I cherry-pick only the changes relevant to MyFolder between MainHashStart..MainHashEnd

You can't. Git isn't about "changes" or "folders". It's about commits. A commit is basically a complete snapshot of the state of the entire working tree of the project at a moment in time. The only thing you can cherry pick is a commit.

You can, however, create a patch, edit it, and apply the edited patch.

Or (what I would do) just use git restore to extract the desired state of the particular individual files from the target commit into the working tree and make a new commit.

huangapple
  • 本文由 发表于 2023年3月9日 20:04:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684361.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定