Search code examples
gitgithubgit-merge

How to merge up to specific commit id from a remote branch in Git


I am working in a forked repository, where all my development work is on the local repo, but then merged back into the fork. We have a long-term development branch, that I would like to sync up with main on occasion.

However, because of the complexity of my dependencies, I don't want to merge directly from the HEAD of main; I want to identify a specific commit, and only merge up to that point.

Two remotes:

  • origin
  • official

I have looked at this question/answer, but it does not seem to address my specific situation.

I am working in origin, but the branch I am merging from is in official. The commit in the history that I hope to merge from is 0c084b4408 (on the official remote repo).

git merge --no-commit official/0c084b4408

When I do this, I get the message merge: official/0c084b4408 - not something we can merge

Easy enough to simply merge from the HEAD of a given branch in the official repo, but merging to a specific commit doesn't seem to be an option.

Is there a way to do this?

Do I need to specify a branch also? I wouldn't have thought so, since a commit is a commit.


Solution

  • Just git merge 0c084b4408, the id is the commit's true name, its real identity. refnames and other revision expressions are resolved to ids very early, that's what the command's trying to do with the string you gave it.