【问题标题】:How to `git reset` After `git merge --no-commit --no-ff`如何在`git merge --no-commit --no-ff`之后`git reset`
【发布时间】:2013-06-21 22:50:53
【问题描述】:

我是 git 的新手。 我正在研究一个涉及大量代码移动的分支,包括删除旧文件和添加新文件。因此,我决定在实际合并之前先进行一次 git merge 的试运行:

我跑了git merge --no-commit --no-ff <myBranchName>。在我运行这个之后,它向我展示了一些冲突。然后我做了 git status 结果是:

My-Macbook-pro:[master] $ git status
# On branch master
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#
# Changes to be committed:
#   modified:   common/TP.php
#   deleted:    common/model/Job/Request.php
#   new file:   common/DP.php
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   both modified:      .gitignore
#   both added:         build/release/current/production.sql
#   deleted by them:    common/Service/DFPASPAdapter.php
#   both modified:      common/Ze.php
#   deleted by them:    common/model/provider/DFPASP.php

然后为了撤消git add(由于git merge 试运行而发生),我运行了git reset HEAD。但后来我意识到/了解到,为了回到 master 分支在合并之前所处的阶段(即与提交给 master 的内容完全相同),我需要运行 git reset --hard HEAD 在我运行硬重置后,git status 显示以下内容:

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   build/release/current/upgrade.php
#   common/F1.php
#   common/F2.php
#   common/F3.php
nothing added to commit but untracked files present (use "git add" to track)

上述文件 F1、F2、F3 和 upgrade.php 已添加到我正在处理的分支中。我希望git reset --hard HEAD 能让master 分支忘记与我尝试合并的分支相关的任何内容(试运行)。

这是可能的吗? 我在这个概念中有什么遗漏吗?我是否只能选择手动删除文件? 任何让我了解更多的帮助都会很棒! 谢谢!

【问题讨论】:

    标签: git git-merge git-reset


    【解决方案1】:

    git 不知道不在索引中的文件。要删除与当前分支无关的文件,包括未跟踪的文件,请运行

    git clean -fd .
    

    【讨论】:

      猜你喜欢
      • 2014-01-17
      • 2011-07-28
      • 2016-05-19
      • 2018-03-27
      • 2012-02-22
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多