Git Pull不可能,未合并的文件 [英] Git Pull is Not Possible, Unmerged Files
问题描述
我已阅读了关于此的所有类似问题;看起来下面没有任何工作:
pre $ 删除违规文件
git reset --hard HEAD
git stash
git pull
几乎所有的组合,在unmergable文件中。我想放弃所有本地更改并只使用远程设备,但我无法再克隆(开发人员尝试执行此操作时带宽和Internet使用限制)。我该怎么做呢?
试过:
git存储
git pull
也没有用。
更多信息
有一个本地提交,上游也有一个提交。因此,我尝试了 git pull --rebase
但它仍然不能正常工作......这给了我错误 - 由于未解决的冲突而退出。如果我做了 git stash,git reset --hard HEAD,git pull --rebase
,我得到错误拉不可能,未合并的更改...如果远程是 origin
并且分支是
master
检出,可能会尝试以下操作: git fetch origin
git reset --hard origin / master
这基本上只是将当前分支指向远程分支的 HEAD
。
警告:正如评论中所述,这会抛弃您的本地更改,会覆盖原始内容。
或者你可以使用管道命令来做基本相同的操作:
git fetch <远程>
git update-ref refs / heads /< branch> $(git rev-parse< remote> /< branch>)
git reset --hard
编辑:我想简单解释一下为什么它能正常工作。
.git
文件夹可以为任意数量的存储库保存提交。由于提交散列实际上是提交内容的验证方法,而不仅仅是随机生成的值,因此它用于在存储库之间匹配提交集。
A分支只是给定散列的命名指针。以下是一个示例集:
$ find .git / refs -type f
.git / refs / tags / v3 .8
.git / refs / heads / master
.git / refs / remotes / origin / HEAD
.git / refs / remotes / origin / master
$ c
这些文件中的每一个都包含一个指向提交的哈希:
$ cat .git / refs / remotes / origin / master
d895cb1af15c04c522a25c79cc429076987c089b
这些都是用于内部git存储机制的,并且独立于工作目录工作。通过执行以下操作:
git reset --hard origin / master
git会将当前分支指向与origin / master指向的相同散列值。然后,它会强制更改工作目录以匹配该散列处的文件结构/内容。
要在工作中看到这一点,请继续尝试以下操作:
git checkout -b测试分支
#查看当前的提交和差异
git show HEAD
#现在指向另一个位置
git reset --hard< remote> /< branch>
#再次查看更改
git show HEAD
I've read all of the similar questions on this; it seems that none of the following have worked:
Delete offending files
git reset --hard HEAD
git stash
git pull
Nearly every combination, stashing changes and pulling from repository, results in unmergable files. I'd like to discard all local changes and just use the remote, but I cannot clone again (bandwidth and internet usage limitations with the developer trying to do this). How do I do this?
Just tried:
git stash
git pull
Also did not work.
More Info
There is one local commit, and the upstream has a commit as well. I've thus tried git pull --rebase
but it's still not working properly... That gives me errors - "exiting because of an unresolved conflict". If I do git stash, git reset --hard HEAD, git pull --rebase
, I get the error "pull is not possible, unmerged changes..."
解决方案 Say the remote is origin
and the branch is master
, and say you already have master
checked out, might try the following:
git fetch origin
git reset --hard origin/master
This basically just takes the current branch and points it to the HEAD
of the remote branch.
WARNING: As stated in the comments, this will throw away your local changes and overwrite with whatever is on the origin.
Or you can use the plumbing commands to do essentially the same:
git fetch <remote>
git update-ref refs/heads/<branch> $(git rev-parse <remote>/<branch>)
git reset --hard
EDIT: I'd like to briefly explain why this works.
The .git
folder can hold the commits for any number of repositories. Since the commit hash is actually a verification method for the contents of the commit, and not just a randomly generated value, it is used to match commit sets between repositories.
A branch is just a named pointer to a given hash. Here's an example set:
$ find .git/refs -type f
.git/refs/tags/v3.8
.git/refs/heads/master
.git/refs/remotes/origin/HEAD
.git/refs/remotes/origin/master
Each of these files contains a hash pointing to a commit:
$ cat .git/refs/remotes/origin/master
d895cb1af15c04c522a25c79cc429076987c089b
These are all for the internal git storage mechanism, and work independently of the working directory. By doing the following:
git reset --hard origin/master
git will point the current branch at the same hash value that origin/master points to. Then it forcefully changes the working directory to match the file structure/contents at that hash.
To see this at work go ahead and try out the following:
git checkout -b test-branch
# see current commit and diff by the following
git show HEAD
# now point to another location
git reset --hard <remote>/<branch>
# see the changes again
git show HEAD
这篇关于Git Pull不可能,未合并的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!