git - 如何在 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 命令工作?
解决方案
就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
推荐阅读
- excel - 执行 If 语句的更快方法
- excel - 将 IF 语句添加到组合框链接单元格 Excel
- puppeteer - Puppeteer:如何像 Jasmine 中的假计时器一样管理时间?
- python - 如何使用 Python 在单个图表上绘制多种数据?
- python - 如何验证数字翻译器?
- razor - TM 符号在 Kendo 窗口标题中呈现为 ™
- spring-boot - spring webflux 如何在 webfilter 中获取请求正文?
- ios - 检索场景中所有可用的 SCNbox、SCNNode 并显示、隐藏它们
- php - 在 foreach 循环中更新数组数据的问题
- c# - DatagridView C# 列的总和