简体   繁体   English

将修改过的文件签出到Git中的新分支

[英]Checkout modified files to new branch in Git

I have recently moved to Git for my organization's project. 我最近搬到Git参加我组织的项目。

I am heading a team of 4 people. 我要领导一个由4个人组成的团队。 They have all forked my copy of the project, now they make changes and send me pull requests. 他们都分叉了我的项目副本,现在他们进行更改并向我发送请求请求。

Let's say I receive a pull request and merge it to the dev branch (which is still pending QA). 假设我收到一个拉取请求,并将其合并到dev分支(仍在等待质量检查)。 In the meantime, there's another pull request which is very critical, another team member took the latest from dev, made a new branch, and applied the fixes in the new branch, then sent me a pull request. 同时,还有一个非常重要的请求请求,另一个团队成员从开发人员那里获取了最新消息,创建了一个新分支,并在新分支中应用了这些修复程序,然后向我发送了一个请求。

The problem is, I just want to pull in the changes made for the critical fix. 问题是,我只想提取对关键修复程序所做的更改。 If at this stage I merge the changes to production, it will also merge the prior changes, which were still awaiting QA. 如果在此阶段我将变更合并到生产中,它也将合并仍在等待质量检查的先前变更。

Is it possible to checkout only files which require changes, so that it will force me to push the current development work on production? 是否可以仅签出需要更改的文件,从而迫使我将当前的开发工作推向生产环境?

I have Googled and found a command git checkout --orphan branchname which will create a blank branch, now after checkout, it will automatically stage the whole project for commit. 我已经用Google搜索了,找到了一个命令git checkout --orphan branchname ,它将创建一个空白分支,现在在签出之后,它将自动为提交整个阶段进行准备。 So I used git reset HEAD -- to unstage everything. 因此,我使用了git reset HEAD -- HEAD-撤消了所有操作。

Now I just added the required files and committed it, but when I raise a pull request to the remote repo, it says both the branches has entirely different history. 现在,我只添加了必需的文件并提交了它,但是当我向远程仓库提出拉取请求时,它说两个分支的历史完全不同。

Can anyone tell me how I could achieve this?. 谁能告诉我如何实现这一目标?

You want to "cherry-pick" the critical fixes. 您想“挑选”关键修复程序。 This just takes the changes in that changeset, without taking anything else. 这仅需要更改集的更改,而无需进行其他任何操作。

  1. Find the changeset hash in your dev branch. 在您的dev分支中找到更改集哈希。
  2. git checkout -b my-critical-fix production
  3. git cherry-pick $HASH

That will give you a branch called "my-critical-fix", based on production, with just the change that you want. 这将为您提供一个基于生产的名为“ my-critical-fix”的分支,其中包含您想要的更改。 Now you can check it and create a pull request against the production branch when you are happy. 现在,您可以检查它,并在满意时对生产分支创建拉取请求。

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

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