git fast-forward one commit

半腔热情 提交于 2020-12-01 10:19:28

问题


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


回答1:


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.




回答2:


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

or

git reset --hard 9aeb07e

instead of merge.



来源:https://stackoverflow.com/questions/45155486/git-fast-forward-one-commit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!