当前位置:   article > 正文

Git合并分支代码的正确方法_git 合并分支代码

git 合并分支代码

1、环境准备

假定您之前已经装好了git,而且已经能git pull、git add、git commit -m “评论”、git push和创建分支等操作;

我的操作目的是:将分支开发的代码合并到主干上,所以使用git checkout master,切换到主干上。

进入Windows PowerShell,cd到你要操作项目的根目录,也就是.git文件所在的目录;

 2、git status

获取当前本地的状态

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.js

Changes 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

暂时缓存本地的修改

PS D:\phpstudy_pro\WWW\program> git stash 

4、git branch -a

 获取所有本地仓库和远程仓库列表

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的分支合并进来

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.js

Changes 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.php

Untracked 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.log

Dropped refs/stash@{0} (790243dd7a185f79caf09283c16706ef26a0c935)

7、git push 

最后别忘了,git push将合过来的新代码上传到远程仓库上

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/908452
推荐阅读
相关标签
  

闽ICP备14008679号