Pregunta

I have a local repo and I want to fast-forward it to a specific commit (which may not be the HEAD of the remote repo).

So I do:

git fetch master
git checkout sha

This however puts me in a detached HEAD state, which I don't want. Is there an equivalent to git checkout -b branch_name sha, which works when branch_name already exist?

In short, I have to update the HEAD of my local repo to a remote commit. I already tried git pull origin sha with no success. I cannot use git pull origin master because that will fast-forward to the HEAD of the remote, while I want to fast-forward to a specific commit.

¿Fue útil?

Solución

If you want to merge up to a specific commit, fetch all remote changes and specify this commit's id:

git fetch origin
git merge <sha1 of commit you want to merge>

You can specify the --ff-only option and have Git fail when it cannot fast-forward (and would create a new merge commit).


If you only want to put a single commit on top of your current branch's tip, use cherry-pick (but this is usually not recommended):

git cherry-pick <sha1 of commit you want to merge>

Otros consejos

you can do this:

checkout master

checkout your sha

then crate branch from the existing sha1

git checkout -f masetr
git checkout SHA1
git checkout -b 'BRANCH_NAME'
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top