每次我在本地的Git存储库上结帐到不同的分支机构时,我都需要执行以下操作:
1. git stash
2. git checkout branch_name
3. git stash pop stash@{0}
这样我就可以通过checked out分支获得我的工作目录和临时目录。
有没有更好更快的方法呢?这是一种技巧/变通方法还是直接的内置命令?
我的方法是通过ZSH别名让它更简单,如下所示:
myfunction() {
git stash
git checkout $1
git stash pop stash@{0}
}
alias gcost=myfunction
发布于 2015-10-02 02:43:06
一种更简单的方法是签出另一个分支,而不需要存储。只要没有冲突,更改就会保留在您的工作副本中(在这种情况下,签出被拒绝,您可以使用stash/ use方法)。换句话说:未提交的更改会自动从一个分支跟踪到另一个分支。
发布于 2015-10-02 00:18:45
我建议下面的流程,我称之为Work-In-Progress (WIP)。
关于错误修复分支
git checkout bug_fix_branch
edit some code
git add -u
git commit -m 'WIP: Fix: Bug in network driver e1000'
在功能分支上
git checkout feature_branch
git cherry-pick commit-id-of-the-above-commit
edit some code
git add -u
git commit --amend # update the last "WIP" commit with the changes
当错误修复或功能准备推送时,只需使用git commit --amend
去掉"WIP“前缀,然后推送即可。
https://stackoverflow.com/questions/32891846
复制相似问题