git命令清单

一、设置和配置

1.初始化一个新的仓库:
git init
2.克隆(Clone)一个远程仓库到本地:
git clone <repository_url>
3.配置用户信息:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

二、基本操作

1.查看文件状态:
git status
2.添加文件到暂存区:
git add <file1> <file2> ...
3.提交更改到版本库:
git commit -m "Your commit message"
4.查看提交日志:
git log

三、分支操作

1.创建新分支:

git branch <branch_name>
2.切换到指定分支:
git checkout <branch_name>

或

git switch <branch_name>
3.创建并切换到新分支:
git checkout -b <new_branch_name>

或

git switch -c <new_branch_name>
 1732  git branch test_1  -- 创建新分支test_1
 1733  git branch -r --查看远程分支
 1734  git checkout test_1 --切换到指定分支test_1
 1735  git status 
 1736  git add.
 1737  git add README.md
 1738  git commit -m "Your commit message"
 1739  git push -u origin master  --此时推送的是master分支,README.md文件并没有修改
 1740  git push -u origin test_1    --此时推送的是test_1分支,README.md文件已经修改
 
 后续在gitlab会出现push request,可以手动创建merge request,并同意;

4.合并分支:
git merge <branch_name>

5.删除分支:

git branch -d <branch_name>

四、远程操作

1.查看远程仓库信息:
git remote -v
2.添加远程仓库:
git remote add <remote_name> <repository_url>
3.从远程仓库拉取更新:
git pull <remote_name> <branch_name>
4.推送本地更改到远程仓库:
git push <remote_name> <branch_name>
5.查看远程分支:
git branch -r

五、撤销和重置

1.撤销工作区的更改:
git restore <file>

或

git checkout -- <file>

举例子:git checkout -- README.md
2.撤销暂存区的更改:
git reset HEAD <file>

举例子:git reset HEAD README.md
3.回滚到之前的提交:
git reset --hard <commit_hash>

六、其他操作

1.查看修改过的文件:
git diff
2.查看分支合并图:
git log --graph --oneline --all
3.查看帮助信息:
git --help

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值