“git checkout main_branch; 的别名” git 合并 topic_branch”?

发布于 2024-08-16 03:10:58 字数 313 浏览 8 评论 0原文

在我们的团队中,我们使用开发、暂存和主分支以及问题分支。通过这个工作流程,我发现自己做了以下很多事情:

例如在开发分支中:

git checkout staging; git merge development

有人有一个简单的别名吗?

它应该是这样的:

merge_with master

会做:

git checkout master; git merge previous_branch

In our team we are using a development, staging and a master branch plus branches for issues. With this workflow I find myself doing a lot of the following:

For example in the development branch:

git checkout staging; git merge development

Does anyone have a simple alias for this?

It should be something like:

merge_with master

would do:

git checkout master; git merge previous_branch

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

日记撕了你也走了 2024-08-23 03:10:58
git checkout master; git merge HEAD@{1}

您可以使用以下命令为其分配一个别名:

git config alias.mm '!git checkout master; git merge HEAD@{1}'

这样 git mm 会将您当前的分支合并到 master 中。

git checkout master; git merge HEAD@{1}

You can assign an alias to that using:

git config alias.mm '!git checkout master; git merge HEAD@{1}'

So that git mm will merge your current branch into master.

冷默言语 2024-08-23 03:10:58

如果发生冲突,git merge 始终在当前分支上执行,因此您必须首先签出暂存分支。

但是,如果允许线性历史记录,您可以使用 git rebasedevelopment staging 。

正如迈克尔所说,你总是可以创建一个别名。

编辑:将其添加到 .git/config 即可

[alias]
    merge_to = !sh -c 'CURRENT=$(git symbolic-ref HEAD) && git checkout $1 && git merge $CURRENT' -

git merge is always performed on the current branch in case of conflict, so you have to checkout the staging branch first.

However, if linear history is permitted, you can use git rebase development staging.

As Michael said, you can always make an alias.

EDIT: Add this to .git/config will do it

[alias]
    merge_to = !sh -c 'CURRENT=$(git symbolic-ref HEAD) && git checkout $1 && git merge $CURRENT' -
dawn曙光 2024-08-23 03:10:58
git config alias.thething '!git checkout staging ; git merge $1'

应该给你一个

git thething development
git config alias.thething '!git checkout staging ; git merge $1'

should give you one as

git thething development
梦中楼上月下 2024-08-23 03:10:58

感谢您的帮助。没有一个完全符合我的要求,但确实让我朝着正确的方向前进。

我已将以下内容添加到 ~/.bash_login 中。对于每个 git 存储库,“merge_to somebranch”都会执行 git checkout somebranch; git 合并上一个分支。

# Git functions to quickly merge branches
# e.g. merge_to staging
function current_branch { ref=$(git symbolic-ref HEAD 2> /dev/null); echo ${ref#refs/heads/} }
function merge_to       { branch=`eval current_branch`; git checkout "$@" && git merge $branch }

Thanks for all your help. None of all did exactly what I wanted but did get me in the right direction.

I have added the following to ~/.bash_login. For every git repository "merge_to somebranch" will do git checkout somebranch; git merge previousbranch.

# Git functions to quickly merge branches
# e.g. merge_to staging
function current_branch { ref=$(git symbolic-ref HEAD 2> /dev/null); echo ${ref#refs/heads/} }
function merge_to       { branch=`eval current_branch`; git checkout "$@" && git merge $branch }
獨角戲 2024-08-23 03:10:58

这就是我的意思,只是它还不起作用。

branch="$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"; echo "git checkout master; git merge $branch"

首先它找出当前分支是什么。然后它使用它来确定要合并的分支。

所以接下来的事情是找出如何附加别名参数......

Here is sort of what I mean except it does not work yet.

branch="$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"; echo "git checkout master; git merge $branch"

First it finds out what the current branch is. Then it uses that to determine which branch to merge with.

So the next thing is to find out how to append an alias argument...

情话已封尘 2024-08-23 03:10:58

我一直在这样做,特别是因为在我们的一个项目中,我们有几个略有不同的生产分支。部署修复/更新可能会让您的手指感到疲劳。

对于所有 Windows 用户:我刚刚在我的 %path% 中的某个位置创建了一个 merge.bat 文件,它包含:

git checkout %1 && git merge %2 --verbose

然后我所做的就是

merge foo bar

它运行:

git checkout foo 
git merge bar --verbose

I'm forever doing this, especially since on one of our projects we have several subtly different production branches. Deploying a fix/update can make your finger's tired.

For all you Windows bods out there: I've just created a merge.bat file somewhere in my %path% and it contains:

git checkout %1 && git merge %2 --verbose

then all I do is

merge foo bar

and it runs:

git checkout foo 
git merge bar --verbose
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文