首页 > 解决方案 > 如何在 git 中合并类似于我的 mercurial 工作流程的分支?

问题描述

注意我使用的是 Windows 10,但我确实可以访问 Ubuntu 20 VM 服务器(无桌面 GUI)。我通过安装tortoisehg安装了 mercurial,它也“礼貌”地安装了KDiff3进行合并。

我正在使用的 git repo 托管在 github 中。我正在使用 Ubuntu 服务器使用各种 Unix 文本编辑器来编辑工作目录文件。

我没怎么用过git。我更精通mercurial。假设我有一个名为的分支beta,它从master. dude.htm我发现自回购开始以来一直存在一个错字。要在两个分支中修复它,我执行以下操作:

hg update master
# Open up my favorite GUI text editor and fix the typo.  Save file
hg commit -m "Fix typo in dude"

在这里,我可能会通过持续集成构建我的项目并验证拼写错误是否已修复。现在我想把它合并到beta

hg update beta
hg merge master
# here TortiseHg will ask me how I want to handle file conflicts 
# and bring up KDiff3 to assist me with merging
hg commit -m "merge master > beta"

这是一个持续多年的坚实过程。我希望能够用这个 git repo 做同样的事情。我希望能够在我的 Windows 机器上编辑这个 git repo 的文件,但我对此有点怀疑,因为我总是遇到围绕行尾(和其他)符号的问题。

我怎样才能像我上面描述的 hg merge 那样执行 git merge ?是否有像 KDiff3 这样的 GUI 可以通过 Ubuntu 命令行 git merge 命令工作?

标签: gitgithubmercurialtortoisehgkdiff3

解决方案


git命令而言:从 cli 中,您将运行

git checkout master
# fix the typo ...

# one change from Mercurial : in git you have to explicitly add the files
# in the staging area (also called 'index') before committing :
git add path/to/dude.htm
                                   # where you explicitly add the files in 
git commit -m "Fix typo in dude"   # or just 'git commit', then type the commit
                                   # message in the editor that opens
  • git add -u:添加所有已在暂存区域中跟踪的文件,
    您可以在提交前查看内容
  • git add -A:将磁盘中的所有文件添加到

运行 CI,测试修复...

合并到beta

git checkout beta
git merge -m "merge master > beta" master

# if the merge triggers merge conflict :
git status        # will highlight the conflicting files

git mergetool     # will open your mergetool of choice (eg: kdiff3), once for each 
                  # conflicting file

# once you have fixed the conflicts, run :
git commit

推荐阅读