简体   繁体   English

我如何合并 git 中类似于我的 mercurial 工作流程的分支?

[英]How do I merge branches in git that is similar to my mercurial workflow?

NB I'm using Windows 10, but I do have access to a Ubuntu 20 VM server (no desktop GUI).注意我正在使用 Windows 10,但我确实可以访问 Ubuntu 20 VM 服务器(无桌面 GUI)。 I installed mercurial by installing tortoisehg which also “courtesy” installs KDiff3 for merging.我通过安装tortoisehg安装了 mercurial,它也“礼貌地”安装了KDiff3用于合并。

The git repo I'm using is being hosted in github. I'm using the Ubuntu server to edit the working directory files using various Unix text editors.我正在使用的 git 存储库托管在 github。我正在使用 Ubuntu 服务器使用各种 Unix 文本编辑器编辑工作目录文件。

I haven't used git much.我没怎么用过 git。 I'm much more proficient in mercurial. Let's say I have a branch called beta that was started from master .我更精通 mercurial。假设我有一个名为beta的分支,它是从master开始的。 I found a typo in dude.htm that has been around since the repo was started.我在dude.htm中发现了一个打字错误,该错误自回购开始以来就一直存在。 To fix it in both branches I do the following:要在两个分支中修复它,我执行以下操作:

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

Here I might build my project via continuous integration and verify the typo has been fixed.在这里,我可能会通过持续集成构建我的项目,并验证拼写错误是否已修复。 Now I want to merge this into 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"

This has been a solid process that's worked for years.这是一个多年来一直有效的可靠流程。 I'd like to be able to do the same thing with this git repo.我希望能够对这个 git 存储库做同样的事情。 I'd like to be able to edit the files of this git repo on my Windows box, but I'm somewhat leery about doing so because I always get into issues revolving around end of line (and other) symbols.我希望能够在我的 Windows 盒子上编辑这个 git 存储库的文件,但我对此持谨慎态度,因为我总是遇到围绕行尾(和其他)符号的问题。

How can I perform a git merge like the hg merge I described above?我怎样才能像上面描述的 hg 合并一样执行 git 合并? Is there a GUI like KDiff3 that will work from an Ubuntu command line git merge command?是否有像 KDiff3 这样的 GUI 可以从 Ubuntu 命令行 git 合并命令运行?

As far as git commands go: from the cli, you would run至于git命令 go:从 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 : add all files that are already tracked in the staging area git add -u : 添加所有已经在暂存区被跟踪的文件
    you can review the content before committing您可以在提交之前查看内容
  • git add -A : add all files from disk in the git add -A : 添加磁盘中的所有文件

Run CI, test the fix...运行 CI,测试修复...

To merge into beta :合并到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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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