撤消失败 merge 时git删除文件

标签 git reset git-merge

我已将 master merge 到我的 bugXY 分支中,需要 merge 一个文件。但是 git mergetool 失败了(我猜是我的菜鸟错误),即使我中止了 merge ,它也给我留下了一个肮脏的工作目录,但并不处于需要 merge 的状态。我想重复 merge 命令,但由于 merge 留下了一些新文件,我不能。

我怎样才能撤消 merge (我没有提交任何内容)并从之前准确获取工作目录?

我做了什么:

> git checkout bugXY
On branch "bugXY" - nothing to commit
> git merge master
[modifying and adding lots of files]
one file with conflict
On branch "bugXY|MERGING"
> git mergetool
You could use a, b or c
merged // didn't work, no GUI appeared and I did not do anything
do you want to remove, commit or abort?
> abort // Hu, what happened?
On branch "bugXY" // no MERGING any more???

糟糕,我做了什么?重复的 git merge 不起作用,我现在已经更改(并暂存)了我工作目录中的文件。好的,撤消它。我试过:

> git reset --hard HEAD

> git checkout bugXY

现在什么都没有上演了,但我仍然有一堆未跟踪的工作树文件,这阻碍了我再次git merge(“会被覆盖,请[重新]移动它们”)。我怎样才能做到这一点?我想 rm path/to/file.php 它们中的每一个都可以工作,但是它们有很多......

最佳答案

如果你没有进行试运行,显示 git 将清除的文件:

git clean -ndx

真正从您的工作树中清除所有这些文件:

git clean -fdx

关于撤消失败 merge 时git删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11025242/

相关文章:

git merge 不是时已经是最新的

mysql - 最好的 git mysql 版本控制系统?

iis-6 - 重置应用程序池会自动关闭所有数据库连接吗?

inputstream - 如何重用/重置ZipInputStream?

git-merge - 不能将 `git mergetool` 与 `git am` 或 `git apply` 或 `patch` 一起使用

xcode - com.apple.dt.Xcode.sourcecontrol.Git 重载 CPU

java - 从头开始构建 Eclipse IDE - 如何指定目标操作系统?

javascript - 停止倒计时并每天显示消息

git - 使用 Actions 在测试通过后自动 merge ?

git - 覆盖 merge 中的本地更改