Git常用命令

本文提供了Git的基本操作指南,包括新建、查看、切换分支,提交、合并代码,以及与远程仓库交互的详细步骤。掌握这些命令能有效提升代码管理效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

新建分支
git branch newbranch

查看分支
git branch

切换分支
git checkout newbranch

查看是否切换到该分支
git branch

提交改动到当前分支
git add.
git commit -a

查看提交状态
git status


切换回主分支
git checkout master

将新分支提交的改动合并到主分支上
git merge newbranch

查看合并后产生的冲突
git diff

再次提交

删除分支
git branch -D newbranch


git add.
git comm -m "提交信息"
代码上传至远程库中
git pull origin master
git push origin master


$ git push origin master
To https://gitee.com/l_jj/bookms.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/l_jj/bookms.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


git pull --rebase origin master

git push -u origin master

和远程仓库建立连接
git remote add origin 远程仓库地址


从远程仓库克隆
git clone 远程仓库地址 本地目录

git仓库初始化
git init


git pull 版本库更新
git add  新增文件加入Git中
git rm   删除
git commit   提交当前工作空间的内容
git push   将本地commit的代码更新到远程版本库中
git log  查看历史日志
git revert 还原某一个版本的修改
git rebase 分支内节点的移动(第一次提交完成时,分支点在a,第二季提交完成时,分支点在b,具有从a->b的能力)
git reset  将当前工作目录完全回滚到制定的版本号

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值