git 工作只进行到一半,还没法提交

把当前工作现场“储藏”起来,等以后恢复现场后继续工作:

$ git stash

首先确定要在哪个分支上修复bug,假定需要在master分支上修复,就从master创建临时分支:

$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 6 commits.
$ git checkout -b issue-101
Switched to a new branch 'issue-101'
修复完成后,切换到 master分支,并完成合并,最后删除 issue-101分支

$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
$ git merge --no-ff -m "merged bug fix 101" issue-101
Merge made by the 'recursive' strategy.
 readme.txt |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git branch -d issue-101
Deleted branch issue-101 (was cc17032).
刚才的工作现场存到哪去了?用 git stash list命令看看:
$ git stash list
stash@{0}: WIP on dev: 6224937 add merge
git stash pop,恢复的同时把stash内容也删了

你可以多次stash,恢复的时候,先用git stash list查看,然后恢复指定的stash,用命令:

$ git stash apply stash@{0}

你可能感兴趣的:(git 工作只进行到一半,还没法提交)