什么是执行git stash,git checkout mybranch,git stash pop的管道命令? [英] What are the plumbing commands to do a git stash , git checkout mybranch, git stash pop?

查看:67
本文介绍了什么是执行git stash,git checkout mybranch,git stash pop的管道命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个执行以下操作的脚本:1)git存储2)git checkout myBranch3)git stash pop

I would like to create a script that does the following: 1) git stash 2) git checkout myBranch 3) git stash pop

哪些git plumbing命令可以代替上面的git ceramic命令?

What are the git plumbing commands that could replace the above git porcelain commands?

基于Mark Adelsberger和Torek非常详细和冗长(谢谢你们)的答案,我将坚持使用瓷器命令.我还想指出以下声明,该声明对何时使用瓷器vs管道命令非常有帮助.

Based on the very detailed and lengthy (thank you guys) answers of Mark Adelsberger and Torek I will stick to use the porcelain commands. I would also like to note the following statement which I found very helpful on when to use porcelain vs plumbing commands.

引自Mark Adelsberger的回答:

Quoted from Mark Adelsberger' s answer :

由于您使用的命令不会产生可驱动脚本的输出,因此我不会为寻找管道等效物而过分担心."

推荐答案

首先,值得快速提醒一下的是 git stash save 的工作方式是重新提交-或实际上,至少两次提交,但是其中之一是主要的一次提交,这就是从那时起使用它的哈希ID.因此,我们可以将其称为隐藏提交":就像其他任何提交一样,除了(a)它位于 no 分支上,以及(b)它看起来像是一个合并提交,但永远不要用作合并提交.

First, it's worth a quick reminder that the way git stash save works is that it makes a new commit—or really, at least two commits, but one of them is kind of a primary one and that's the hash ID one uses to work with it from then on. So we can refer to this as "the stash commit": it's just like any other commit except that (a) it's on no branch, and (b) it looks like a merge commit, but should never be used as a merge commit.

git stash 命令本身是一个非常复杂的脚本,没有直接的管道等效项.但是,(自Git 1.8.4起)它确实有自己的方式,可以通过 git stash create (可选地,接着是 git stash store 为存储项分配一个名称).

The git stash command itself is a very complicated script that has no direct plumbing equivalent. However, it does (since Git 1.8.4) have its own way to be used as plumbing, via git stash create (optionally followed by git stash store to assign the stash commit a name).

创建步骤会进行 git stash save 会进行的隐藏提交,但不会为其分配 stash @ { number } 条目,以便所有现有存储区都以通常的方式命名.请注意,就像 git stash save 一样,如果没有东西可以存储,它什么也不会做. git stash save 的输出是新的主要stash提交的哈希ID,如果没有新的提交,则根本不输入.

The create step makes the stash commit that git stash save would make, but does not assign it a stash@{number} entry, so that all the existing stashes are named in the usual way. Note that just like git stash save, it does nothing at all if there is nothing to stash. The output from git stash save is the hash ID of the new primary stash commit, or nothing at all if there is no new commit.

如果这会创建一个隐藏提交,则您有14天(默认情况下)为它命名或完成使用.如果您希望命令序列花费超过14天的时间,则可能需要使用 git stash store 将其作为 stash @ {0} 推送到存储堆栈中,并重新编号所有其他人合而为一.如果您认为脚本会在14天的宽限期内完成,那么您甚至不需要发明名称:您只需将存储提交哈希传递给 git stash apply .

If this creates a stash commit, you have 14 days (by default) to give it a name or finish using it. If you expect your command sequence to take more than 14 days, you might want to use git stash store to push it onto the stash stack as stash@{0}, renumbering all the others up one. If you think your script will finish within the 14 day grace period, you don't even need to invent a name: you can just pass the stash commit hash to git stash apply.

因此:

commit=$(git stash create)
... do your thing here ...
if [ "$commit" != "" ]; then git stash apply $commit; fi

(如 Mark Adelsberger指出的,您应该检查 apply 是否成功,如果没有成功,,您可能应该给隐藏提交一个名称).

(as Mark Adelsberger noted you should check whether the apply succeeded, and if not, you should probably give the stash commit a name).

对于 git checkout 来说,管道等效项有点复杂(它包括自动确定结帐是否成功,然后如果成功,则使用 git symbolic-ref 使用 git read-tree git checkout-index 来重新绑定 HEAD ,以更新索引和工作树以匹配新的 HEAD 提交,保留可以保留的索引和工作树修改).如果您成功完成了 git stash save 或等效操作,则仅在以下情况下出现剩余的失败情况:

As for git checkout, the plumbing equivalent is a bit complicated (it consists of atomically determining whether the checkout will succeed, and then if so, using git symbolic-ref to re-bind HEAD while using git read-tree and git checkout-index to update the index and work-tree to match the new HEAD commit, preserving index and work-tree modifications that can be preserved). If you've just done a successful git stash save or equivalent, the only remaining failure cases occur when:

  • 有一些未跟踪的文件(工作树中的文件,但不在索引中的文件)将通过切换提交而被跟踪,或者
  • 索引中有设置为-skip-worktree -假定未更改的文件,这些文件将在索引中更改(因此在工作树),通过切换提交
  • there are untracked files (files in the work-tree but not in the index) that will become tracked by switching commits, or
  • there are files in the index with either --skip-worktree or --assume-unchanged set, that will be changed in the index (and hence in the work-tree) by switching commits

因此有可能几乎将其简化为一些简单的管道命令.但是 git checkout 分支名称 的设计目的是可用作管道.您可能也可以使用它.

so it's almost possible to reduce this to some simple plumbing commands. But git checkout branchname is designed to be usable as plumbing anyway. You probably might as well just use it.

这篇关于什么是执行git stash,git checkout mybranch,git stash pop的管道命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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