我是git的新手。 我正在开发一个涉及大量代码移动的分支,包括删除旧文件和添加新文件。因此我决定在实际合并之前做一个干运行的git合并:
我跑了git merge --no-commit --no-ff <myBranchName>
。我跑了之后,它向我展示了一些冲突。然后我做了git状态,结果是:
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
。但后来我意识到/了解到为了回到舞台,主分支在合并之前就已进入(即与提交给主人的内容完全相同),我需要运行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
分支忘记与我试图合并的分支相关的任何事情(干运行)。
这是可能的吗? 这个概念中是否有我遗漏的东西?我是否离开了手动删除文件的唯一选择? 任何让我了解更多的帮助都会很棒! 谢谢!
答案 0 :(得分:1)
git不知道索引中没有的文件。要删除与当前分支无关的文件,包括未跟踪的文件,请运行
git clean -fd .