Rob
Rob

Reputation: 947

git pull and lose any local changes

I have a CI system which pulls code from Github for testing. 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:

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:

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.

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?

Upvotes: 0

Views: 1469

Answers (1)

eftshift0
eftshift0

Reputation: 30156

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.

Upvotes: 4

Related Questions