Git: move a branch to make it point to another -


i had following situation:

-----o      |    master    branch1 

then had make changes master:

 -----o-----o-----o       |           |    branch1      master 

now want branch1 @ same point of master (and therefore contain commits made):

-----o-----o-----o                  |                master                branch1 

i don't know if merge correct way achieve this. steps should take?

edit: consider have uncommitted changes should committed on branch1 after branch1 date master. need current changes left untouched committed later on branch1

since branch1 references commit ancestor of master, merge operation won't result in merge commit; instead, git move branch1 reference forward references same commit master. called fast-forward merge.

from documentation:

when try merge 1 commit commit can reached following first commit’s history, git simplifies things moving pointer forward because there no divergent work merge – called “fast-forward.”

so, in case, can say:

git checkout branch1 git merge master 

which make branch1 point same commit master.

update: note need have clean working directory before doing merge. if have uncommitted changes in branch1 (i.e. have dirty working directory), should first store them away in stash using git-stash command:

git stash save --include-untracked -m "work in progress" 

once changes saved , working directory clean, can proceed merge. afterwards, can restore files stash saying:

git stash pop 

which put files in working directory , remove them stash. @ point, can choose commit them in numbers of commits.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -