简体   繁体   English

git 拉取并丢失任何本地更改

[英]git pull and lose any local changes

I have a CI system which pulls code from Github for testing.我有一个 CI 系统,它从 Github 中提取代码进行测试。 It starts out with a clone of the repo and then, when a new commit appears, it is given the hash of the commit and does:它从 repo 的克隆开始,然后,当出现新的提交时,它会被赋予提交的 hash 并执行以下操作:

git pull --no-rebase origin <hash>

git -c advice.detachedHead=false checkout --no-progress <hash>

No changes are ever made to the code, nothing is ever pushed, only pulled.没有对代码进行任何更改,没有任何东西被推送,只是被拉取。

However, every so often git pull fails with a merge conflict:然而, git pull经常会因合并冲突而失败:

Pulling is not possible because you have unmerged files. hint: Fix them up in the work tree, and then use 'git add/rm <file>' hint: as appropriate to mark resolution and make a commit. fatal: Exiting because of an unresolved conflict.

When this happens I've tried doing git reset --hard as a recovery mechanism and doing the pull once more but that does not help, the same merge conflict prevents the pull from working and I'm stuck.发生这种情况时,我尝试git reset --hard作为恢复机制并再次进行pull ,但这无济于事,同样的合并冲突阻止了pull取工作,我被卡住了。

Can anyone tell me the bit of git magic that I'm missing which will always make every pull succeed, vaping the [non existent] local changes?谁能告诉我我缺少的一点 git 魔法,它总是会让每次pull都成功,消除 [不存在的] 本地更改?

If you just want to do tests on said revision, why do you pull into a local branch (and face this kind of messes that happen when you try to merge stuff)?如果您只想对上述修订进行测试,为什么要拉入本地分支(并面对尝试合并内容时发生的这种混乱)? Try fetching and checking out instead:尝试获取并签出:

git fetch origin
git checkout <hash>

That should do.应该这样做。 No more need to deal with conflicts or what-not.不再需要处理冲突或其他问题。 You should even consider try a git clean -f in the process if possible so that files that were generated as part of the (previous) build process disappear as well.如果可能,您甚至应该考虑在此过程中尝试git clean -f ,以便作为(先前)构建过程的一部分生成的文件也消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM