【问题标题】:git fast-forward one commitgit 快进一次提交
【发布时间】:2017-12-22 15:43:06
【问题描述】:
* 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

这是我(最近)的历史。

我希望 feature/QOL-1649-install-chrome 上移一个提交,到 9aeb07e

我尝试了cherry pick,但随后我得到了该提交的“副本”到feature/QOL-1649-install-chrome 分支。但我想要(我认为)是快进。

【问题讨论】:

    标签: git fast-forward


    【解决方案1】:
    git checkout feature/QOL-1649-install-chrome
    git merge --ff-only 9aeb07e
    

    git reset --hard 9aeb07e
    

    而不是合并。

    【讨论】:

      【解决方案2】:

      您可以使用git reset,但为了一般的安全和清洁,我更喜欢使用git merge --ff-only。要使用它,请查看您想要快进的分支(您已经拥有),然后运行git merge --ff-only <commit-hash>

      git merge --ff-only 9aeb07e
      

      我经常使用这个命令,所以我给它起了一个别名,git mff(快进合并)。


      编辑,2020 年 11 月:请注意,您不必在此处使用原始哈希 ID; git mff origin/somebranch 也可以正常工作。您可以在此处使用原始哈希。这是 Git 中一般规则的一部分:如果您可以使用原始哈希,则可以使用分支名称、标签名称、远程跟踪名称等。

      围绕这条一般规则有一些特殊情况,特别是,如果您将原始哈希 ID 与 git checkout 命令一起使用,您将得到 Git 所谓的 分离的 HEAD,而如果您使用带有git checkout 的分支名称,您将“在分支上”(即,附加的 HEAD: 与分离的相反,尽管 Git 文档从未这样称呼它:它只是说“在树枝上”)。 Git 2.23 及更高版本中的新 git switch 命令对此更好,因为如果它要切换到 detached-HEAD 模式,它要求您添加 --detach 选项。但是,有了这个 git mff 别名,就不用担心特殊情况了。

      【讨论】:

      • 谢谢。我尝试了git reset,它成功了,但是git merge 的安全感让我更快乐!
      • 这对我来说是一样的——我运行git fetch,然后运行git mff而不是git pull。如果 mff 失败,然后我会查看是否要合并或变基。如果 mff 成功,它几乎总是我想要的。
      猜你喜欢
      • 2021-03-08
      • 1970-01-01
      • 2011-06-03
      • 2011-01-21
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      相关资源
      最近更新 更多