如何修复因中断而停止的 git 合并?
How to fix a git merge that was stopped in between with an interrupt?
我正在修改几个文件。然后我尝试将代码推送到存储库中。为此,我使用了以下命令:
git add <FILENAME1>
git commit -m "explanation of merge"
git pull
此时拉取失败并显示消息:
error: Your local changes to the following files would be overwritten by merge:
(FILENAME2).
Please commit your changes or stash them before you merge.
所以我尝试了以下命令:
git checkout FILENAME2
git pull
然而,此时 git 拉动卡住了。我现在意识到也许我应该在拉动之前再次使用 运行 "git commit" 命令。这就是导致 git 卡住的原因吗?
我等了大约 10 分钟,什么也没发生。然后我使用 cntrl+C 中止了它。但是,现在我看到已经创建了一个新分支。
如果早些时候我在 (branch-1) 那么现在我在 (branch-1|MERGING).
谁能解释一下这是怎么回事?如何返回分支 1 和 同时保留我的文件名 1?
注: 运行宁一个git状态显示如下:
Changes to be committed:
modified: FILENAME2
modified: FILENAME1
然后尝试找到您的最后一次提交 ID,您需要使用以下命令将您的存储库重置为最后一次提交状态:
git reset --hard commitId
完成后,您可以选择使用
在单独的分支中保护您的工作
git check-out -b savedBranch
git check-out branch1
然后你需要拉 branch1 因为有人在你之前推你可以正确合并
否则,如果您不想创建新分支,您可以使用以下方式简单地对推送代码的工作进行 rebase
git rebase origin/branch1
此命令将尝试使您在处理分支之前已将其拉出
然后纠正冲突
git add . (Note: This will add all modified files and untracked files that's result of the rebase conflicts correction into the staging)
git rebase --continue
你需要多少次都可以
那就尽情享受吧! :)
我建议您在命令行中使用 linux 的 tig 实用程序,以便更好地查看您的提交
我正在修改几个文件。然后我尝试将代码推送到存储库中。为此,我使用了以下命令:
git add <FILENAME1>
git commit -m "explanation of merge"
git pull
此时拉取失败并显示消息:
error: Your local changes to the following files would be overwritten by merge:
(FILENAME2).
Please commit your changes or stash them before you merge.
所以我尝试了以下命令:
git checkout FILENAME2
git pull
然而,此时 git 拉动卡住了。我现在意识到也许我应该在拉动之前再次使用 运行 "git commit" 命令。这就是导致 git 卡住的原因吗?
我等了大约 10 分钟,什么也没发生。然后我使用 cntrl+C 中止了它。但是,现在我看到已经创建了一个新分支。
如果早些时候我在 (branch-1) 那么现在我在 (branch-1|MERGING).
谁能解释一下这是怎么回事?如何返回分支 1 和 同时保留我的文件名 1?
注: 运行宁一个git状态显示如下:
Changes to be committed:
modified: FILENAME2 modified: FILENAME1
然后尝试找到您的最后一次提交 ID,您需要使用以下命令将您的存储库重置为最后一次提交状态:
git reset --hard commitId
完成后,您可以选择使用
在单独的分支中保护您的工作git check-out -b savedBranch
git check-out branch1
然后你需要拉 branch1 因为有人在你之前推你可以正确合并
否则,如果您不想创建新分支,您可以使用以下方式简单地对推送代码的工作进行 rebase
git rebase origin/branch1
此命令将尝试使您在处理分支之前已将其拉出
然后纠正冲突
git add . (Note: This will add all modified files and untracked files that's result of the rebase conflicts correction into the staging)
git rebase --continue
你需要多少次都可以
那就尽情享受吧! :)
我建议您在命令行中使用 linux 的 tig 实用程序,以便更好地查看您的提交