1

我是 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分支忘记与我试图合并的分支相关的任何内容(试运行)。

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

4

1 回答 1

1

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

git clean -fd .
于 2013-06-21T22:56:15.060 回答