1

I realize there are similar answers, such as the one found here, but these expect that you know the structure of GitHub commits and branches, and I don't.

So my question is if I want to pull a commit 12fds123nfd1123sefs12 from branch master on GitHub, what is the git fetch command?

For clarity, I mean I want to pull all commits up to a given commit.

Community
  • 1
  • 1
Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90
  • 1
    Can you do `git fetch && git checkout 12fds123nfd1123sefs12`? I don't think you can retrieve an individual commit, since it is based on all the commits that went before it. – halfer Aug 20 '15 at 09:12
  • how about "`git show 12fds123nfd1123sefs12 `"? – Michael Dautermann Aug 20 '15 at 09:13
  • 1
    What exactly are you trying to achieve? Tell us why you need to pull this specific commit – neshkeev Aug 20 '15 at 09:13
  • 1
    Hmm, there is something on your linked question about getting single commits though - [see here](http://stackoverflow.com/a/30701724/472495). It's a `fetch` with a depth of 1. – halfer Aug 20 '15 at 09:15
  • @halfer but that supposes GitHub has set the config `uploadpack.allowReachableSHA1InWant` (and has a Git 2.5). That isn't sure at all. – VonC Aug 20 '15 at 09:36
  • @zaratustra because some dumbass committed broken code afterwards and i need to update a customer to the latest code base before the break – Matthew James Davis Aug 20 '15 at 09:52
  • -1: I think you are mixing terms. Are you sure you want to _pull_ the specific commit and not _checkout_ it? Also keep in mind that commits in Git don’t belong to branches, they are absolute. A branch is just a pointer to a commit. – Melebius Aug 20 '15 at 10:10
  • Matthew, all you need to do is to pull master, checkout to a hash prior to the break, and branch at that point. You can then deploy the branch. – halfer Aug 20 '15 at 10:59
  • @VonC, thanks - ah, that sounds like a server-wide setting, fair enough. – halfer Aug 20 '15 at 11:01

1 Answers1

4

You have at least two ways to achieve that: the first one is to remove all the commits that are after the desired commit. Interactive rebase will help you:

$ git rebase 12fds123nfd1123sefs12 -i

You will see a text editor, you have to remove everything in it, then save it and forcely update the remote branch:

$ git push origin master -f

The second way is to create a branch based on the desired commit and then release this branch:

$ git checkout -b fixedmaster 12fds123nfd1123sefs12

Now you have the fixedmaster branch that doesn't have any bad commits. You can release it.

neshkeev
  • 6,280
  • 3
  • 26
  • 47
  • Thus spuke zaratustra. #clever – Matthew James Davis Aug 20 '15 at 12:28
  • 1
    To remove all commits after a given SHA1, us `git reset --hard sha1`. `git rebase -i` won't do the trick, since removing everything will abort the interactive rebase. (Moreover, `git reset` is made exactly for this purpose and much more convenient to use.) – Sven Marnach Aug 20 '15 at 14:35