Git reset branch to remote/master keeping logs -
i think know answer i'll ask anyhow.
i work on fork branching. have upstream , origin latter fork.
then create branches origin/new-feature (from on nf). nothing exotic. :)
so after experimenting while in nf , having pushed experiments origin work i've done it's not gonna fly.
reset local , origin with
$ git checkout upstream-master $ git pull $ git checkout nf $ git reset --hard upstream/master $ git push --force now question. there way keep history of old commits in same branch?
if i'd liked keep them have created new branch origin/nf-abandoned before going reset above.
yes, git rebase for. operate on checked-out branch (the source) , branch given on command line (the target) , replay history of source point diverges target onto target new commits, retaining author timestamp commit messages.
$ git checkout origin/new-feature $ git fetch upstream $ git rebase upstream/master $ git push --force origin new-feature the result: (c commit branched from)
a -- b -- c -- d -- e (original origin/new-feature) \-- f -- g (upstream/master) \-- d` -- e` (rebased origin/new-feature) note commits d , e rewritten d` , e` on top of upstream/master, keeping history linear.
alternatively, can instead merge upstream/master branch , continue development, if project accept such pull request. advantage of approach exact history recorded, including merge action, means --force isn't required push branch origin.
$ git checkout origin/new-feature $ git fetch upstream $ git merge upstream/master $ git push origin new-feature the result:
v (original origin/new-feature) -- b -- c -- d -- e -- h <- (post-merge origin/new-feature) \-- f -- g --/ ^ upstream/master
Comments
Post a Comment