1、環(huán)境準(zhǔn)備
假定您之前已經(jīng)裝好了git,而且已經(jīng)能git pull、git add、git commit -m “評(píng)論”、git push和創(chuàng)建分支等操作;
我的操作目的是:將分支開發(fā)的代碼合并到主干上,所以使用git checkout master,切換到主干上。
進(jìn)入Windows PowerShell,cd到你要操作項(xiàng)目的根目錄,也就是.git文件所在的目錄;
?2、git status
獲取當(dāng)前本地的狀態(tài)
PS D:\phpstudy_pro\WWW\program> git status
On branch master
Your branch is up to date with 'origin/master'.Changes to be committed:
? (use "git restore --staged <file>..." to unstage)
? ? ? ? new file: ? client/coupon.php
? ? ? ? new file: ? server/view/base/main_chat.html
? ? ? ? new file: ? server/view/js/complaint/datatables_template.jsChanges not staged for commit:
? (use "git add <file>..." to update what will be committed)
? (use "git restore <file>..." to discard changes in working directory)
? ? ? ? modified: ? server/user/adapay_apply.html
? ? ? ? modified: ? server/user/buy_list.html
3、git stash
暫時(shí)緩存本地的修改
PS D:\phpstudy_pro\WWW\program> git stash?
4、git branch -a
?獲取所有本地倉(cāng)庫(kù)和遠(yuǎn)程倉(cāng)庫(kù)列表
PS D:\phpstudy_pro\WWW\program> git branch -a
* master
? multi_client
? remotes/origin/HEAD -> origin/master
? remotes/origin/master
? remotes/origin/multi_client
?5、 git merge --no-ff remotes/origin/multi_client -m "合并分支代碼"
? 將分支叫multi_client的分支合并進(jìn)來(lái)
PS D:\phpstudy_pro\WWW\program> git merge --no-ff remotes/origin/multi_client -m "合并多端聊天代碼"
Merge made by the 'ort' strategy.
?client/chat.php ? ? ? ? ? ? ? ?| ?1 +
?client/user.php ? ? ? ? ? ? ? ?| 16 +++++++++++++++-
?im/app/Events.php ? ? ? ? ? ? ?| 26 +++++++++++++++++++++++++-
?server/user/apply_binding.html | ?2 +-
?4 files changed, 42 insertions(+), 3 deletions(-)
6、git stash pop
將之前git stash緩存的“本地修改”再還原到本地
PS D:\phpstudy_pro\WWW\program> git stash pop
On branch master
Your branch is ahead of 'origin/master' by 12 commits.
? (use "git push" to publish your local commits)Changes to be committed:
? (use "git restore --staged <file>..." to unstage)
? ? ? ? new file: ? client/coupon.php
? ? ? ? new file: ? server/view/base/main_chat.html
? ? ? ? new file: ? server/view/js/complaint/datatables_template.jsChanges not staged for commit:
? (use "git add <file>..." to update what will be committed)
? (use "git restore <file>..." to discard changes in working directory)
? ? ? ? modified: ? server/user/adapay_apply.html
? ? ? ? modified: ? server/user/buy_list.html
? ? ? ? modified: ? server/user/goods_list.html
? ? ? ? modified: ? server/view/base/main_goods.html
? ? ? ? modified: ? server/view/base/main_user.html
? ? ? ? modified: ? server/view/complaint/main_community_comment.html
? ? ? ? modified: ? server/view/complaint/main_earnest.html
? ? ? ? modified: ? server/view/js/approve/main_set_badge.js
? ? ? ? modified: ? server/view/js/approve/sms_batch.js
? ? ? ? modified: ? server/view/js/common/load_sys_menu.js
? ? ? ? modified: ? server/view/js/login/login.js
? ? ? ? modified: ? server/view/login.html
? ? ? ? modified: ? server/view/main.html
? ? ? ? modified: ? test.phpUntracked files:
? (use "git add <file>..." to include in what will be committed)
? ? ? ? .htaccess
? ? ? ? nginx.htaccess
? ? ? ? res/images/2023-04-17/
? ? ? ? res/images/2023-04-18/
? ? ? ? res/images/instructions.webp
? ? ? ? vendor/workerman/workerman.logDropped refs/stash@{0} (790243dd7a185f79caf09283c16706ef26a0c935)
7、git push?
最后別忘了,git push將合過(guò)來(lái)的新代碼上傳到遠(yuǎn)程倉(cāng)庫(kù)上文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-523359.html
PS D:\phpstudy_pro\WWW\program> git push
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done. ? ? ? ? ? ? ? ? ? ? ? ??
Writing objects: 100% (1/1), 245 bytes | 245.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 ? ? ? ?
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/saycome/php-program.git
? ?6fb11c88..cc6c41f8 ?master -> master文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-523359.html
到了這里,關(guān)于Git合并分支代碼的正確方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!