40

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.

random
  • 9,774
  • 10
  • 66
  • 83
gregghz
  • 3,925
  • 7
  • 40
  • 69
  • Duplicate: http://stackoverflow.com/questions/867831/merge-changes-from-remote-github-repository-to-your-local-repository – jweyrich Jan 03 '11 at 02:55
  • That's asking to pull into the fork, not into the upstream (although it's probably the same method?). I'm also curious to know if there is a way to pull a specific commit instead of the entire branch. – gregghz Jan 03 '11 at 02:58
  • correct, the same applies to the inverse. Oh true, the specific commit part is correctly answered by @Dustin. – jweyrich Jan 03 '11 at 03:31

3 Answers3

50

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.

jweyrich
  • 31,198
  • 5
  • 66
  • 97
Dustin
  • 89,080
  • 21
  • 111
  • 133
  • what's the "commit-to-cherry-pick"? I don't know what belongs there ... is it a url, or some other type of identifier? – gregghz Jan 03 '11 at 03:45
  • nevermind, I figured out that it's the hash of the commit. Thanks! – gregghz Jan 03 '11 at 04:12
  • the hash of the commit, or any other way of referring to it, such as "HEAD~2" if it was two commits back from where HEAD currently is. – Tyler Jan 06 '11 at 07:24
  • 4
    You may need to include the fork's branch name: `git fetch git://github.com/user/project.git branchname` – rmtheis Jun 14 '15 at 00:39
2

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.

Community
  • 1
  • 1
1

Try to use the /forkqueue on github. There you can merge commits to your fork.

Or go to the tab "Network" and select "Forkqueue"

frank_neff
  • 952
  • 8
  • 16