git:结帐时自动隐藏+弹出

gue*_*tli 12 git git-stash

如果我做git checkout my-super-branchgit 告诉我:

error: Your local changes to the following files would be overwritten by checkout:
    somedir/somefile.py
Please, commit your changes or stash them before you can switch branches.
Aborting
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以告诉 git 自动执行 stash+pop?

fra*_*enz 5

结账时没有自动存储的命令行选项。我创建了一个checkout.sh这样的脚本:

#!/bin/bash
git stash && git fetch && git checkout $1 && git stash pop
Run Code Online (Sandbox Code Playgroud)

所以我可以将它与我选择的分支一起使用:checkout.sh my-branch


Vin*_*ati 3

Git 允许流水线操作:

git stash && git fetch && git checkout your-branch && git stash apply

你的改变仍然stash和我使用的一样git stash apply

如果有冲突,请解决。

如果您希望在上述调用后从存储中删除更改:

git 存储下降

否则你可以使用git stash pop

  • `&&` 是 shell 的功能,而不是 Git 的功能。 (10认同)