Git:如何在 pull/自动 merge 失败后恢复文件?

标签 git

我正要通过 git pull origin master 获取最新信息,并意识到我在某些配置文件中存在冲突。但我还有其他文件要 checkin ,我不想丢失这些文件。

由于这些冲突是本地配置文件,我只是删除了它们,希望通过执行新的 pull 请求来再次检索它们。

现在尝试做另一个git pull origin master,它说

"Pull is not possible because you have unmerged files. please, fix them up in the work tree, and then use 'git add/rm ' as appropriate to mark resolution, or use 'git commit -a'."

那么如何从存储库中恢复这些已删除的配置文件并使其保持最新状态? (我不关心这些文件的本地更改,因此我删除了它)

我现在应该对每个配置文件执行以下操作:

git checkout --path/to/individual_file

谢谢

最佳答案

如果您有一些文件要提交,您可以使用 git stash stash 它们,然后使用 git reset --hard HEAD 重置回 HEAD code>,使用 git pull pull 更改,修复所有冲突,然后使用 git stash apply

将存储应用到新的 HEAD 上

如果您希望存储本地更改、重置并 pull 主服务器以及从临时分支恢复本地更改,您还可以创建临时分支

关于Git:如何在 pull/自动 merge 失败后恢复文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13820082/

相关文章:

git 接收后 Hook "empty ident name"

git - 如何使用 tortoisegit 从许多 repo 协议(protocol)中提取?

git - 在 Bitbucket Repo 中恢复 merge 的分支

c - access() 说文件存在但 fopen() 说它不存在

git - 通过本地存储库进行 Azure 部署

gitkraken 'refs/heads/master' 落后于 'refs/remotes/origin/master'

git - 为什么我不能将 git log --follow 与 --full-diff 一起使用?

git - 为什么 "git rebase"在阶段和工作副本中留下相反的修改集?

GitHub pull 请求 : How to merge and fast-forward to avoid "recent changes" and diff notifications

Xcode 无法检查 who to blame 信息