简体   繁体   中英

Checkout modified files to new branch in Git

I have recently moved to Git for my organization's project.

I am heading a team of 4 people. 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). 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. So I used git reset HEAD -- to unstage everything.

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.
  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. Now you can check it and create a pull request against the production branch when you are happy.

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