如果我做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?
小智 23
git checkout -m target-branch
Run Code Online (Sandbox Code Playgroud)
或者
git checkout --merge target-branch
Run Code Online (Sandbox Code Playgroud)
https://git-scm.com/docs/git-checkout/en#Documentation/git-checkout.txt---合并
结账时没有自动存储的命令行选项。我创建了一个checkout.sh这样的脚本:
#!/bin/bash
git stash && git fetch && git checkout $1 && git stash pop
Run Code Online (Sandbox Code Playgroud)
所以我可以将它与我选择的分支一起使用:checkout.sh my-branch
Git 允许流水线操作:
git stash && git fetch && git checkout your-branch && git stash apply
你的改变仍然stash和我使用的一样git stash apply。
如果有冲突,请解决。
如果您希望在上述调用后从存储中删除更改:
git 存储下降
否则你可以使用git stash pop
| 归档时间: |
|
| 查看次数: |
3505 次 |
| 最近记录: |