git fast-forward one commit
Asked Answered
T

2

17
* 9dbd857 (hotfix-correct-java-jdk-path, feature/add-ansible-galaxy-requirements-file) requirements.yml: adds maven and nodejs requirements
* 1643619 (QOL-1640-enable-vpc-peering) roles/ansible-linux-commons: change value of hostname in cloud-init
* b5fd2a4 roles/bamboo-agent: add bitbucket ssh host key to /etc/ssh/ssh_known_hosts
* d5cc1f7 vpc cfn template: produce outputs conditionally
* 3b87efe vpc cfn template: use csv for subnet/AZ mapping
* 2e93096 roles/bamboo-agent: Install chrome on agents
* 9aeb07e roles/bamboo-agent: install chromium browser
* 89e852d (HEAD -> feature/QOL-1649-install-chrome) README: display the current directory structure of inventories
* 1f55c4b inventories/test: define root volume size
* 07d902e bamboo-ec2 cfn: specify root volume size

This is my (recent) history.

I want feature/QOL-1649-install-chrome to move up one commit, to 9aeb07e.

I tried cherry pick, but then I get a "copy" of that commit onto the feature/QOL-1649-install-chrome branch. But what I want (i think) is a fast-forward.

Tynishatynwald answered 18/7, 2017 at 0:14 Comment(0)
C
38

You can git reset to it, but for general safety and cleanness, I prefer to use git merge --ff-only. To use it, check out the branch you want fast-forwarded (you have already), then run git merge --ff-only <commit-hash>:

git merge --ff-only 9aeb07e

I use this command so often that I made an alias for it, git mff (merge fast forward).


Edit, Nov 2020: note that you do not have to use a raw hash ID here; git mff origin/somebranch works fine too. You can use a raw hash here. This is part of a general rule in Git: if you can use a raw hash, you can use a branch name, a tag name, a remote-tracking name, and so on.

There are a few special cases around this general rule, and in particular, if you use a raw hash ID with the git checkout command, you will get what Git calls a detached HEAD, while if you use a branch name with git checkout, you will be "on the branch" (i.e., an attached HEAD: the opposite of detached, although Git documentation never calls it this: it just says "on a branch"). The new git switch command, in Git 2.23 and later, is better about this in that if it's going to switch to detached-HEAD mode, it demands that you add the --detach option. With this git mff alias, however, there's no special case to worry about.

Celie answered 18/7, 2017 at 0:24 Comment(3)
Thank you. I tried git reset and it worked, however the [feeling of] security of git merge makes me happier!Tynishatynwald
It's the same for me—I run git fetch, then git mff instead of git pull. If the mff fails, I then look at whether I want to merge or rebase. If the mff succeeds it's nearly always what I wanted.Celie
What is unsafe with git reset --hard?Apoplectic
F
5
git checkout feature/QOL-1649-install-chrome
git merge --ff-only 9aeb07e

or

git reset --hard 9aeb07e

instead of merge.

Fluted answered 18/7, 2017 at 0:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.