Reputation: 5676
I have two git repos that I cloned on my local machine. I'm attempting to apply a change from one repo to the other:
cd path/to/local-repo1
git fetch path/to/local-repo2 <sha1>
// cherry-pick from fetch head, etc.
I'm getting:
fatal: Couldn't find remote ref <sha1>
fatal: The remote end hung up unexpectedly
I found git: Apply changes introduced by commit in one repo to another repo, but why is it that git does not recognize the sha1 in another local repo? Turns out that if I replace the sha1 with the name of a branch, it succeeds, but I need to do this with a multitude of sha1's and don't really want to create a branch on each one in order to reference them.
Upvotes: 1
Views: 601
Reputation: 468041
The form of git fetch
that you're trying to use is:
git fetch <repository> <refspec>
However, your SHA1sum is (unlikely to be!) a valid refspec. A refspec defines a mapping between refs (usually branch names) between the source and destination repository. SHA1sums (object names) are distinct from refs, and the error is telling you that when you do git fetch path/to/local-repo2 f414f31
, it's expanding the refspec to f414f31:f414f31
and then failing to find the ref f414f31
in the remote repository. That's because it's not a ref.
So, assuming that your commit is on local branch in the remote repository, I would do the following:
git remote add other-local path/to/local-repo2
git fetch other-local
git cherry-pick f414f31
The form git fetch <remote-name>
fetches all the local branches in the remote repository to remote-tracking branches under refs/remotes/<remote-name>
, and makes sure that all the objects necessary for those branches (including all the commits in the history) are present in your local repository.
Upvotes: 1