用git创建一个临时分支名称 [英] create a temporary branch name with git

查看:208
本文介绍了用git创建一个临时分支名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题稍有关系我想与一个临时分支合作在一个shell脚本中。

有点类似于:

  cd $(git rev-parse --show-toplevel)&& 
git subtree split --prefix = some_subfolder -b temp&&
git push my_remote temp:publication_branch -f

现在,我不确定这是什么如果分支 temp 已经存在,在任何情况下我都不希望 my_remote / publication_branch 的结果为取决于此。而且我也不想修改分支 temp (假设我对它有不相关的东西)。最后,我还会在最后做一个清理工作。

  cd $(git rev-parse --show-toplevel)& ;&安培; 
git subtree split --prefix = some_subfolder -b temp&&
git push my_remote temp:publication_branch -f
git branch -D temp

所以我在寻找的是一种创建临时分支名称的方法,它类似于 mktemp ?有没有可以创建一个临时分支名称的git命令?

解决方案

对于这个特定的任务,您可以使用split而不用<$ c

lockquote

成功拆分后,一个单独的提交ID被打印到标准输出。这对应于新创建的树的HEAD,无论您想要如何操作,您都可以操作该树。


所以

  split_head =`git subtree split --prefix = some_subfolder` 
git push my_remote$ split_head:publication_branch -f


Slightly related to this question I'd like to work with a temporary branch in a shell script.

somewhat along the lines of :

cd $(git rev-parse --show-toplevel) &&
git subtree split --prefix=some_subfolder -b temp &&
git push my_remote temp:publication_branch -f

Now, I'm not sure what this will do if the branch temp already exists, in any case I don't want the result on my_remote/publication_branch to depend on that. And I also don't want to modify the branch temp (assuming I have it for something unrelated). At best, I would also do a cleanup at the end

cd $(git rev-parse --show-toplevel) &&
git subtree split --prefix=some_subfolder -b temp &&
git push my_remote temp:publication_branch -f
git branch -D temp

So what I'm looking for is a way to create a temporary branch name that doesn't exist yet, similar to mktemp? Is there a git command which can create a temporary branch name?

解决方案

For this specific task you can use split without -b, by using this (from its manual):

After splitting successfully, a single commit id is printed to stdout. This corresponds to the HEAD of the newly created tree, which you can manipulate however you want.

So

split_head=`git subtree split --prefix=some_subfolder`
git push my_remote "$split_head":publication_branch -f

这篇关于用git创建一个临时分支名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆