代码之家  ›  专栏  ›  技术社区  ›  Tom Hale

git存储退出0,但未创建存储

  •  1
  • Tom Hale  · 技术社区  · 6 年前

    有人劝我 avoid git pull --autostash ,并使用:

    git alias.pull-autostash '!git stash push && git pull --rebase && git stash pop'
    

    $ git stash push
    

    给予:

    No local changes to save
    

    0

    任何 stash pop 那会怎么样 pop 没有被推的东西。

    git commit --allow-empty ?

    2 回复  |  直到 6 年前
        1
  •  3
  •   torek    6 年前

    对于脚本,请使用 git stash create git stash store 将创建的存储作为 stash@{0} ,如果且仅当实际创建了一个。

    git存储创建 git rev-parse refs/stash 运行前后 git stash save 1 这些可以:

    • 第一个失败了,第二个成功了:以前没有藏匿的,现在有了,因此创造了一个。
    • 两个都成功了,两个输出字符串匹配(未创建存储)或不同(创建了存储)。

    因此,如果你使用 --quiet --verify

    old=$(git rev-parse --quiet --verify refs/stash)
    git stash save || die ...
    new=$(git rev-parse --quiet --verify refs/stash)
    if [ "$old" != "$new" ]; then
        made_stash=true
    else
        made_stash=false
    fi
    ... do things ...
    if $made_stash; then ... do things with the stash you made ...
    

    git stash git pull 除非在非常有限的特殊情况下。我和他们有过太多不愉快的经历。)


    1 如果你的Git缺少 git存储创建 git stash push git存储保存 相反。

        2
  •  1
  •   Richard    6 年前

    首先检查是否有挂起的更改(请参阅 https://stackoverflow.com/a/3879077/3526980 )

    $ git alias.pull-autostash '(git diff-index --quiet HEAD -- && git pull --rebase) || (git stash push && git pull --rebase && git stash pop)'