git - How can I discard remote changes and mark a file as "resolved"? -
i have local files, pull remote branch , there conflicts. know keep local changes , ignore remote changes causing conflicts. there command can use in effect "mark conflicts resolved, use local"?
git checkout has --ours option check out version of file had locally (as opposed --theirs, version pulled in). can pass . git checkout tell check out in tree. need mark conflicts resolved, can git add, , commit work once done:
git checkout --ours . # checkout our local version of files git add -u # mark conflicted files merged git commit # commit merge note . in git checkout command. that's important, , easy miss. git checkout has 2 modes; 1 in switches branches, , 1 in checks files out of index working copy (sometimes pulling them index revision first). way distinguishes whether you've passed filename in; if haven't passed in filename, tries switching branches (though if don't pass in branch either, try checking out current branch again), refuses if there modified files that effect. so, if want behavior overwrite existing files, need pass in . or filename in order second behavior git checkout.
it's habit have, when passing in filename, offset --, such git checkout --ours -- <filename>. if don't this, , filename happens match name of branch or tag, git think want check revision out, instead of checking filename out, , use first form of checkout command.
i'll expand bit on how conflicts , merging work in git. when merge in else's code (which happens during pull; pull fetch followed merge), there few possible situations.
the simplest you're on same revision. in case, you're "already date", , nothing happens.
another possibility revision descendent of yours, in case default have "fast-forward merge", in head updated commit, no merging happening (this can disabled if want record merge, using --no-ff).
then situations in need merge 2 revisions. in case, there 2 possible outcomes. 1 merge happens cleanly; of changes in different files, or in same files far enough apart both sets of changes can applied without problems. default, when clean merge happens, automatically committed, though can disable --no-commit if need edit beforehand (for instance, if rename function foo bar, , else adds new code calls foo, merge cleanly, produce broken tree, may want clean part of merge commit in order avoid having broken commits).
the final possibility there's real merge, , there conflicts. in case, git of merge can, , produce files conflict markers (<<<<<<<, =======, , >>>>>>>) in working copy. in index (also known "staging area"; place files stored git add before committing them), have 3 versions of each file conflicts; there original version of file ancestor of 2 branches merging, version head (your side of merge), , version remote branch.
in order resolve conflict, can either edit file in working copy, removing conflict markers , fixing code works. or, can check out version 1 or other sides of merge, using git checkout --ours or git checkout --theirs. once have put file state want it, indicate done merging file , ready commit using git add, , can commit merge git commit.
Comments
Post a Comment