how to reset git repository once and for all into a clean state -


i not work git or linux command line , seems mess lot. windows person , use cygwin emulate environment.

situation:

i have multiple repositories tracked, 1 work on , few others read me.

sometimes, when not pull them long time (one on 2k commits ahead of me) git status tells me, branches have diverged. not know how happens, 2k commits behind , 1 ahead. pulling fails due files causing conflicts, cannot resolved.

this leaves me issue, have repository cannot pull anymore, because has conflicts.

so question is: how can pull repository again without running conflicts? not care changes.

this solution have each time messes up:

git log --max-parents=0 head # copy id on bottom git reset --hard <id-you-have-copied> git clean -f -d git pull 

this stupid , have in 1 command. know of git aliases, have no idea, how commit id command 1 command 2. fine shell script can put somewhere, me, should dynamic, without hard coded id.

it looks have reset branch behind faulty non-existent commit , can forward again

is there obvious missing?

i not sure git --max-parents=0 head command is.

but guess instead (origin & master may replaced desired remote , branch names):

git fetch origin master git reset --hard fetch_head git clean -f -d 

this resets current branch pointer , working tree latest fetched commit (and removes untracked files in same manner command).

note: removes local changes in repository, both committed , not committed changes. (committed changes can still restored referring git reflog though)


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -