更新时间:2022-06-08 03:11:04
1.从主分支(master)上创建开发分支(dev)。
git branch dev
git checkout dev
git add ./src ./res git commit -m "添加缓存模块"
这个时候有一些改变了没有提交的代码会变红色,在你 切换到master之前,应该暂存当前dev的开发一下到栈里。
git stash
1.切换到master。
git checkout master
admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (dev) $ git checkout master Switched to branch 'master' Your branch is up-to-date with 'origin/master'. admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master) $ git pull Username for 'http://gitlab.urd.com': zengjinlong Password for 'http://zengjinlong@gitlab.urd.com': fatal: Authentication failed for 'http://gitlab.urd.com/kankan/kankananime.git/' admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master) $ git pull Username for 'http://gitlab.urd.com': zengjinlong Password for 'http://zengjinlong@gitlab.urd.com': Already up-to-date. admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master) $
git checkout dev
git rebase master
1.切换到master。
git checkout master
git merge dev
git push
4.看你心情,保留或者删除dev分支。
回到dev开发,要从stash中取出暂存的状态
git stash pop
总结流程如下:
git clone URL (master branch now) git branch dev (new dev bransh to develop) git checkout dev (switch dev bransh now) (.....coding ..add ... delete..modify...) git add ./src ./res (just add src and res in the local reposity) git stash (push the status into git stack,as some files modified but not add and committed) git checkout master git pull (update the code from server .) git checkout dev git rebase master (rebase from master.) (solve the conflict code) git checkout master git merge dev (merge the code from dev) git push (upload the new code to server) git checkout dev git stash pop (ok, continue coding ,man )
如果不小心在master分支改动了代码怎么办?
git stash表示的是暂存从上一个commit到现在的改动,一旦你执行了该指令,当前分支会回退到上一次commit时候的状态。所以如果你master改动了。你可以如下处理
git status (you will the modification is red) git stash (temporary store the modification into stack) git status (no red file now, as the branch rallback to the latest commit) git pull (update the code from the server) (if you want to save the modification, you need still step on following steps) git checkout dev git rebase master (update the code base on master) git stash pop (pop the stored code out)