Cherry pick from remote
git cherry-pick SHA1 --no-commit git add --patch
Hopefully that helps anyone else with the same question!
EDIT: OK, maybe it isn't quite that simple. Here are the full steps:
- First you have to be in your repository, do the necessary cd-ing to get to your working directory.
- You now need to add the remote branch, and then fetch it. Do this by:
git remote add someUser git://github.com/someUser/someRepo.git
git fetch someUser
You can now run commands such as git log someUser/master to find the commit SHA1 you want to merge in 'partially'.
Once you have the SHA, you can now run:
git cherry-pick -n SHA1
where SHA1 is the commit SHA, duh!
There quite possibly will be conflicts, depending how old the commit is, and how often that particular area of the project changes. Sorry, but you have to manually resolve these with your trusty editor. So pull out VIM, or whatever else you use, and hack away at the conflicts until you get to the stage where you like the changes.
You now have to reset the index to the HEAD revision, then you can then use the trusty
GIT add --patch
command to pick and choose what changes you want:
git reset HEAD
git add --patch or git add -p
- Yay! Commit time:
git commit -m "I merged a select amount of changes"
- To clean up the mess (The stuff you said no to in git add --patch) and only keep the selected changes in your working repository, run:
git reset --hard HEAD
Apparently git checkout -f is another option as well.
I'm glad you found git add -p; it's extremely powerful. If you already have the commit in question (e.g. didn't use --no-commit on the cherry-pick, or it's one of your commits), you can use git reset HEAD^ to rewind the index a commit back, then add the changes back in with git add -p, committing in steps. If the commit's not at the branch tip, you can use git rebase -i and choose to edit the commit in question. – Jefromi Sep 10 '09 at 16:11
nice walk-through. remember if you just want the entire commit, you just emit the -n in step 4. Like this:git cherry-pick SHA1 – Hulvej Oct 17 at 8:01
Created on: 12th October, 2022
Last updated: 12th October, 2022
Source: Using GIT, how can I selectively merge changes from one commit on another 'fork'? - Stack Overflow
Tagged With: