Git branch diverged -


i new git, although understand it's concept don't think understand it's practice well.

i given branch, uitest work on, because may have not done push, commit, pull correctly, have diverged branch.

because new here, n don't want override other devs codes code or changes experimental used git , how works wouldn't mind discarding changes have copy of need re-do everything.

$ git status # on branch uitest # branch , 'origin/uitest' have diverged, # , have 47 , 6 different commits each, respectively. # nothing commit (working directory clean) 

how undiverge? discard changes , pull recent changes latest changes , continue working without messing other peoples work.

also, new this, little descriptive answer may not make sense me.

many thanks

there few ways.

merge

first, merge origin/uitest, doesn't leave clean history in introduces looks branch , merge though meant same branch along. believe linus liked call these kind of merge commits "pointless". unfortunately, easiest approach.

rebase

rebasing tends more advanced topic , can introduce whole host of other problems if aren't careful. said, it's great way clean history without pointless commits. in case, do:

git rebase origin/uitest 

from uitest branch, , take work did, , put on top of work in origin/uitest.

there couple of catches though. first, if you've merged other branches branch, git rebase drop them. need pass -p flag keep merge commits introduced, that's not right thing either. if did commit own changes, should fine command i've given about.

second, time use rebase should remember never rebase public commits. rebase change commit ids because parents have changed. if people merging work, , rebase it, they'll end several copies of commits in history--which badness. careful when apply technique.

all said, want make git rebase friend. it's powerful , useful tool, power tool, can dangerous.

discard work

if want discard you've done, can run:

git reset --hard @{u} 

or

git reset --hard origin/uitest 

that reset uitest branch match upstream or origin/uitest. discard commits.

personally, i'd rebase work or @ least give try. if fails, or becomes complicated merge conflicts, can abort git rebase --abort, , fallback merge or discarding changes (although merging show same merge conflicts).


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -