简体   繁体   中英

Difference between merge from Master and merge from branch in git

suppose I have a branch b1, done my development, pushed to the remote, and I want to merge into the remote master.I just wandering what's the difference between

git fetch
git checkout b1
git merge/rebase master
git push master

and

git fetch
git checkout master
git merge/rebase b1
git push master

In first case the b1 will have all changes from master , but b1 could have something which is not in master .

The second case - opposite.

Just try to see different combinations in the log before/after merges: git log b1..master , git log master..b1 .

Before the merges, your repo looks something like

...-- * -- * -- * -- * master

...-- * -- * -- * -- * b1

After git merge/rebase master , only master consists of the merged history:

-- * -- * -- * -- * -- * master
                      /
...-- * -- * -- * -- * b1

After git merge/rebase b1 , only b1 consists of the merged history:

...-- * -- * -- * -- * master
                      \
-- * -- * -- * -- * -- * b1

You probably want the first scenario, where you normally branch off master and would want the full history including all previous merges. However, if b1 is a long-lived branch, you may occasionally do the second merge as well, so that b1 keeps up-to-date with master .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM