git stash封存分支 以及关于开发新功能的处理
Posted 爬行的龟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git stash封存分支 以及关于开发新功能的处理相关的知识,希望对你有一定的参考价值。
有种情况,我们要修复项目的bug时,但别的分支有修改的代码,要修复的bug可能会影响(所有分支共用一个暂存区)。可以单独创建一个bug分支,用于修复和提交bug,在修改前可以先stash封存分支修改的代码。
测试,首先在slave分支里修改文件:456的内容,然后执行git stash 封存slave分支未提交的代码。
[email protected] MINGW64 /c/laoni/PycharmProjects/github_test (master) $ git checkout slave Switched to branch ‘slave‘ [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git status On branch slave nothing to commit, working tree clean [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ ls 456 998 bb.css index.html info.py new [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ cat 456 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ vim 456 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ cat 456 修改456文件 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git stash warning: LF will be replaced by CRLF in 456. The file will have its original line endings in your working directory. Saved working directory and index state WIP on slave: 6957dae add 998 HEAD is now at 6957dae add 998 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git stash No local changes to save [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git log --oneling fatal: unrecognized argument: --oneling [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git log --oneline 6957dae add 998 775f3ab add new 6abf028 modify info.py a068c80 add info.py c5b475a Revert "add 123" cfcbd5c add 456 13f5bcb add 123 8110523 Revert "add adc" 74f7cb6 add bb.css 577fab6 Revert "revert abc" e1f2701 add adc 358cdac 添加UI.js 04c94a8 添加一个文件index.html
创建bug01分支,并修复和提交bug文件:998,然后切换到master分支,合并bug01分支
$ git branch bug01 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git branch bug01 master * slave [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git checkout bug01 Switched to branch ‘bug01‘ [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (bug01) $ vim 998 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (bug01) $ cat 998 fsaldkfsalfjlasjfl 修复bug内容部分 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (bug01) $ git status On branch bug01 Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: 998 no changes added to commit (use "git add" and/or "git commit -a") [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (bug01) $ git add 998 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (bug01) $ git commit -m "monify bug 998" [bug01 487e2eb] monify bug 998 1 file changed, 1 insertion(+) [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (bug01) $ git checkout master Switched to branch ‘master‘ [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (master) $ git merge merge mergetool [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (master) $ git merge bug01 --no-ff -m "merge bug01" Merge made by the ‘recursive‘ strategy. 998 | 1 + 1 file changed, 1 insertion(+) [email protected]ESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (master) $ git log --oneline f698663 merge bug01 487e2eb monify bug 998 85bd6ea add dd.css bdba943 merge slave --no--ff 6957dae add 998 112da02 modify new 775f3ab add new 8b5d2fd add new 6abf028 modify info.py a068c80 add info.py c5b475a Revert "add 123" cfcbd5c add 456 13f5bcb add 123 8110523 Revert "add adc" 74f7cb6 add bb.css 577fab6 Revert "revert abc" e1f2701 add adc 358cdac 添加UI.js 04c94a8 添加一个文件index.html
最后再解封slave,使用git stash pop可以解封最近的一次封存,使用git stash apply 封存编号可以解封指定的封存位置。
$ git checkout slave Switched to branch ‘slave‘ [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git status On branch slave nothing to commit, working tree clean [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git stash list [email protected]{0}: WIP on slave: 6957dae add 998 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git stash pop On branch slave Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: 456 no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/[email protected]{0} (3ef365731c328973f18469b046770d7fa1b55e41) [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git stash Saved working directory and index state WIP on slave: 6957dae add 998 HEAD is now at 6957dae add 998 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git stash list [email protected]{0}: WIP on slave: 6957dae add 998 [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $ git stash apply [email protected]{0} On branch slave Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: 456 no changes added to commit (use "git add" and/or "git commit -a") [email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (slave) $
以上是关于git stash封存分支 以及关于开发新功能的处理的主要内容,如果未能解决你的问题,请参考以下文章