随笔 - 741  文章 - 0  评论 - 260  阅读 - 416万

git merge

'Normal' Merge

In case of a normal merge, a merge commit with at least two parent commits (i.e., the last from the current branch and the last from the merged branch) is created. See the following figure, where > indicates where the HEAD is pointing to:

                            o [> master]
                            |\
o [> master]                o \
|                  ==>      |  |
|  o [a-branch]             |  o [a-branch]
.  .                        .  .

Fast-forward Merge

If the current branch is completely included in the branch to be merged with (i.e. the latter is simply a couple of commits ahead), then no extra merge commits is created. Instead, the branch pointer of the current branch is moved forward to match the branch pointer of the other branch, as shown below:

o [origin/master]             o [> master][origin/master]
|                     ==>     |
o [> master]                  o
.                             .

In SmartGit, there are several places from which you can initiate a merge:

  • Menu and toolbar On the main window, select Branch |Merge to open the Merge dialog, where you can select the branch to be merged into the current branch. Depending on your toolbar settings, you can also open this dialog via the Merge button on the toolbar.
  • Branches view In the Branches view (available both on the main window and the Log window), you can right-click on a branch and select Merge to merge the selected branch into the current branch.
  • Log Graph On the Log graph of the Log window, you can perform a merge by right-clicking on a commit (usually the one where the branch to be merged with points to) and selecting Merge from the context-menu.

Regardless of how you invoked the Merge command, you will be given the choice between Create Merge-Commit and Merge to Working Tree, and optionally also Fast-Forward if a fast-forward merge is possible.

If you choose Create Merge-Commit, SmartGit will perform the merge and create a merge commit, assuming there are no merge conflicts. If there are merge conflicts, or if you choose Merge to Working Tree, SmartGit will perform the merge, but leave the working tree in a merging state, so that you can manually resolve merge conflicts and review the changes to be made. See Resolving Conflicts for further information on how to deal with merge conflicts.

Squash Merge

The squash merge works like a normal merge, except that it discards the information about where the changes came from. Hence it only allows you to create normal commits. The squash merge is useful for merging changes from local (feature) branches where you don't want all of your feature branch commits to be pushed into the remote repository.

                            o [> master] (changes from a-branch)
                            |
o [> master]                o
|                  ==>      |
|  o [a-branch]             |  o [a-branch]
.  .                        .  .

On the Commit dialog, you can choose between a normal merge (merge commit) and a squash merge (simple commit). Thus, to perform a squash merge you have to choose Merge to Working Tree when initiating the merge, since otherwise you won't see the Commit dialog.

Merge versus Rebase

A Git-specific alternative to merging is rebasing (see Rebase), which can be used to keep the history linear. For example, if a user has made local commits and performs a pull with merge, a merge commit with two parent commits - the user's last commit and the last commit from the tracked branch - is created. When using rebase instead of merge, Git applies the local commits on top of the commits from the tracked branch, thus avoiding a merge commit.

Resolving Conflicts

When a merge, a cherry-pick (or its counterpart, the revert) or a rebase fails due to conflicting changes, SmartGit stops the operation and leaves the working tree in a conflicted state, so that you can either abort the operation, or resolve the conflicts and continue with the operation. This section explains how you can do that with SmartGit. Generally, the following options are available:

  • Resolve dialog If you select a file containing conflicts and then invoke Local |Resolve in the menu of SmartGit's main window, you can set the file's contents to either of the two conflicting versions, i.e. `Ours' or `Theirs'. Optionally, you may also choose not to stage the resetting of the file contents, meaning that the conflict marker on that file won't be removed.
  • Conflict Solver Selecting a file containing conflicts and invoking Query |Conflict Solver will open the Conflict Solver, a three-way diff between the two conflicting versions (left and right editor) and a third version (center editor) that contains the conflicting hunks from both sides, along with conflict markers. You can directly edit the text in the center editor, and you can move changes from the left and right side into the center by clicking on the arrow and `x' buttons between the editors.
  • Discard command To abort the merge, cherry-pick, revert or rebase, select the repository in the Repositories view and invoke Branch |Abort or Local |Discard.

Lastly, if all conflicts have been resolved, you can continue with the merge, cherry-pick or rebase by selecting the repository in the Repositories view and invoking Local |Commit. If you are rebasing, the Commit toolbar button has changed its name to Continue.

posted on   莫水千流  阅读(1034)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
历史上的今天:
2017-04-01 do{...}while(0)的意义和用法
2012-04-01 c函数文件读写
2012-04-01 如何使用MFC和类型库创建自动化项目
2012-04-01 认识配置设置文件(INI与XML)
2012-04-01 VC++多线程编程
2012-04-01 fopen时w与wb的区别
2012-04-01 在VC中彻底玩转Excel 转
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示