Someone forked a Github project of mine and made some changes. How can I merge the changes back in to my upstream version?
Also, is it possible to pull in just a specific commit?
What I'm looking is if there is a way to pull a specific commit instead of the entire branch.
To pull down (i.e. copy) the changes merged into your fork, you can use the Terminal and the git pull command. To begin: On your local computer, navigate to your forked repo directory. Once you have changed directories to the forked repo directory, run the command git pull .
Pulling in a single commit would be a cherry-pick and would rewrite the commit ID (and mark you as the committer while retaining the author). The process is pretty straightforward, though:
git fetch git://github.com/user/project.git git cherry-pick <SHA-COMMIT-ID>
You get the SHA from the repository log, for example:
git log --oneline b019cc0 Check whether we have <linux/compiler.h>. 0920898 Include <linux/compiler.h> before including <linux/usbdevice_fs.h>. cbf0ba1 Add DLT_DBUS, for raw D-Bus messages. 77ed5cd Libnl 2.x returns its own error codes, not errnos; handle that.
With git cherry-pick 0920898
you bring the respective commit to your current branch.
There is an awesome tool which is called hub, which provides useful tools to clean up pull requests and generally "helps you win at git".
One useful command in this context is:
git am -3 <url>
This allows you to grab the changes from a url and apply its commits/changes to your current local git without even fetching the remote repository (which comes in handy with large repositories).
If you use this command with the git webpage of the commit you want to grab, you end up with this commit in your git. Even more useful: the commit author is kept and not replaced by you (as it would if you use git rebase
). If you push this to your repo, the changes will be committed by you, but authored by the original author.
A very good ressource on this topic is this guide by Nathaniel Talbott. It shows a great workflow to work with pull requests instead of relying on the "malicious" merge pull request button on github.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With