git 相当于 hg mq?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/952651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:42:05  来源:igfitidea点击:

git equivalent to hg mq?

gitmercurialmercurial-queue

提问by John Weldon

I just started using Git alongside Mercurial to familiarize myself with Git.

我刚刚开始将 Git 与 Mercurial 一起使用,以熟悉 Git。

I use the mq extension in Mercurial extensively to manage local patches, and I'm looking for a Git equivalent.

我广泛使用 Mercurial 中的 mq 扩展来管理本地补丁,并且我正在寻找一个 Git 等效项。

Should I just use Git branch? Or are there better ways to manage local patches that enable easily applying and removing the patches?

我应该只使用 Git 分支吗?或者是否有更好的方法来管理本地补丁,以便轻松应用和删除补丁?

Thanks,

谢谢,

采纳答案by Jakub Nar?bski

Check out "Patch-management Interface layers" section of Interfaces, Frontends And Toolspage on Git Wiki. There are listed two patch management interfaces, roughly equivalent to Mercurials 'mq' extension:

查看Git Wiki 上接口、前端和工具页面的“补丁管理接口层”部分。列出了两个补丁管理接口,大致相当于 Mercurials 'mq'扩展名

  • StGIT(Stacked Git), older of the two, written in Python, uses two snapshots to represent patch
  • Guilt(formerly 'gq'), written as series of bash scripts, series file and the patches (one per file) are stored as plain text file.
  • pg (Patchy Git) is deprecated, and no longer maintained.
  • StGIT(Stacked Git),两者中较旧的,用 Python 编写,使用两个快照来表示补丁
  • Guilt(以前称为“gq”),编写为一系列 bash 脚本、系列文件和补丁(每个文件一个)存储为纯文本文件。
  • pg (Patchy Git) 已弃用,不再维护。

But if you don't need more advanced usage, you can use instead "git rebase --interactive" to reorder, squash and split patches. And to manage your branch against current version of upstream, "git rebase" usually would suffice.

但是如果你不需要更高级的用法,你可以使用“ git rebase --interactive”来重新排序、压缩和分割补丁。并且要根据上游的当前版本管理您的分支,“git rebase”通常就足够了。

回答by CB Bailey

Disclaimer: I'm not an hg user, so I have read about hg but don't have much first hand experience of using it.

免责声明:我不是 hg 用户,所以我已经阅读了有关 hg 的内容,但没有太多使用它的第一手经验。

git provides several very powerful and flexible tools for managing branches in a 'patch queue' style so for many basic (and even some quite complex) use cases, native git is sufficiently powerful.

git 提供了几个非常强大和灵活的工具,用于以“补丁队列”样式管理分支,因此对于许多基本(甚至一些非常复杂的)用例,原生 git 已经足够强大了。

Typically, most projects keep a central stable master branch which only gains new commits and is never 'rewound' so commits in the master branch are fixed.

通常,大多数项目保持一个中央稳定的 master 分支,它只会获得新的提交并且永远不会“回滚”,因此 master 分支中的提交是固定的。

On top of this a maintainer (or a developer) may maintain one or more fluid branches of work-in-progress patches (i.e. commits) which are based on the stable branch.

在此之上,维护者(或开发者)可以维护一个或多个基于稳定分支的正在进行的补丁(即提交)的流动分支。

Typical patch managing activities include:

典型的补丁管理活动包括:

rebasing the patch queue onto the lastest stable branch - use git rebase,

将补丁队列重新定位到最新的稳定分支 - 使用git rebase

duplicating the patch queue onto an old maintentance branch - use git branchand git rebase,

将补丁队列复制到旧的维护分支 - 使用git branchgit rebase

reordering patches in the queue - use git rebase --interactive(aka git rebase -i) using a text editor to reorder the queue.

重新排序队列中的补丁 - 使用git rebase --interactive(又名git rebase -i)使用文本编辑器重新排序队列。

squashing patches - use git rebase -iwith the squash directive

挤压补丁 -git rebase -i与壁球指令一起使用

altering patches or patch commit messages - use git rebase -i(spot a theme?) with the edit directive.

更改补丁或补丁提交消息 - 使用git rebase -i(发现主题?)与编辑指令。

Any activity that alters a patch in any way (i.e. its contents, description or parentage) will create a new commit with a new commit id for that patch. The fact that the old commits may be thrown away and replaced regularly before they are promoted to the stable master branch is the only thing that makes them a 'patch queue' rather than a branch, but this is a project convention rather than any physical difference in the data that makes up the commits. To git they are identical objects.

任何以任何方式(即其内容、描述或出身)更改补丁的活动都将为该补丁创建一个具有新提交 ID 的新提交。旧提交在被提升到稳定的主分支之前可能会被丢弃并定期替换这一事实是唯一使它们成为“补丁队列”而不是分支的事实,但这是项目约定而不是任何物理差异在构成提交的数据中。git 它们是相同的对象。

To promote a patch to a 'real' commit is just moving the patch to the front of the queue and merging it into the master branch. After moving the patch to the front of the queue, it is just the same as a normal commit based on the master branch, so merging it just fast-forwards the master branch pointer to point at the patch commit.

将补丁提升为“真正的”提交只是将补丁移到队列的前面并将其合并到主分支中。将补丁移到队列前面后,它与基于主分支的普通提交相同,因此合并它只是将主分支指针快进指向补丁提交。

Publishing this commit as a 'stable' master patch is the act that says: this is now a commit that will not change and is part of the immutable history of the project.

将此提交发布为“稳定”主补丁的行为表明:现在这是一个不会更改的提交,并且是项目不可变历史的一部分。

回答by Dustin

Just use a branch and rebase it against your upstream branch regularly. This is both easier to manage and safer than using mq (to which I've lost data in the past).

只需使用一个分支并定期将其重新设置为针对您的上游分支。这比使用 mq(我过去丢失了数据)更容易管理和更安全。

回答by C Pirate

Git doesn't really provide this feature itself. Depending on your uses, you might be able to get by with "git stash" and/or branches, but it'll be pretty basic. If people have more advanced patch management needs with git, they seem to turn to Quilt or StGit: see http://git.or.cz/gitwiki/PatchManagement

Git 本身并没有真正提供此功能。根据您的用途,您可能可以使用“git stash”和/或分支,但这将是非常基本的。如果人们对 git 有更高级的补丁管理需求,他们似乎会转向 Quilt 或 StGit:参见http://git.or.cz/gitwiki/PatchManagement