Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git fast-forward one commit

* 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.

like image 661
Felipe Alvarez Avatar asked Jul 18 '17 00:07

Felipe Alvarez


People also ask

What is Git fast forward only?

Fast-forward merges literally move your main branch's tip forward to the end of your feature branch. This keeps all commits created in your feature branch sequential while integrating it neatly back into your main branch.

How do I fast forward a Git master?

If master has not diverged, instead of creating a new commit, git will then simply point master to the latest commit of the feature branch. This is a "fast forward". We can create a new commit to represent the merge even if git would normally fast forward by passing "--no-ff" .

What is a FF merge?

A fast-forward merge can occur when there is a linear path from the current branch tip to the target branch. Instead of “actually” merging the branches, all Git has to do to integrate the histories is move (i.e., “fast forward”) the current branch tip up to the target branch tip.


2 Answers

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.

like image 145
torek Avatar answered Sep 28 '22 03:09

torek


git checkout feature/QOL-1649-install-chrome
git merge --ff-only 9aeb07e

or

git reset --hard 9aeb07e

instead of merge.

like image 31
phd Avatar answered Sep 28 '22 02:09

phd