git常用命令以及简易原理图

本文详细介绍了Git的常用命令,包括初始化、工作区管理、历史查看、分支操作、合并与冲突解决、远程仓库交互等。通过实例展示了如何克隆、创建、切换、推送和拉取分支,以及如何撤销修改、回退版本和删除文件。此外,还涵盖了与远程仓库的交互,如查看远程信息、推送和拉取操作,以及分支的创建、删除和链接设置。
摘要由CSDN通过智能技术生成

原理图:
三个对象构成多种变化
在这里插入图片描述

git [common commands]

这些是在各种情况下使用的常见Git命令

start a working area
  • clone Clone a repository into a new directory
    init Create an empty Git repository or reinitialize an existing one
work on the current change
  • add Add file contents to the index
    mv Move or rename a file, a directory, or a symlink
    reset Reset current HEAD to the specified state
    rm Remove files from the working tree and from the index
examine the history and state
  • bisect Use binary search to find the commit that introduced a bug
    grep Print lines matching a pattern
    log Show commit logs
    show Show various types of objects
    status Show the working tree status
grow, mark and tweak your common history
  • branch List, create, or delete branches
    checkout Switch branches or restore working tree files
    commit Record changes to the repository
    diff Show changes between commits, commit and working tree, etc
    merge Join two or more development histories together
    rebase Reapply commits on top of another base tip
    tag Create, list, delete or verify a tag object signed with GPG
collaborate
  • fetch Download objects and refs from another repository
    pull Fetch from and integrate with another repository or a local branch
    push Update remote refs along with associated objects

git 的常用命令

和远程仓库有关

要查看远程库
git remote
要查看远程库de更详细的信息:
git remote -v

克隆远程仓库,【默认情况下只能看到本地的master分支】
git clone git@github.com:XXX/XXX.git

创建远程origin的dev分支到本地,【本地和远程分支的名称最好一致】
git checkout -b dev origin/dev

推送本地分支
git push origin dev

推送失败,败抓取远程的新提交;
git pull
成功拉取但是有冲突,需要手动解决【去文件里面修改后】,解决后,提交【git commit -m “fix conflict”】,再push【git push origin dev】:

git pull如果失败,则设置dev和origin/dev的链接

指定本地dev分支与远程origin/dev分支的链接
git branch --set-upstream-to=origin/dev dev

分支有关

查看本地分支
git branch

创建本地分支
git branch branchname

创建并切换到本地分支
git checkout -b branchname
git switch -c branchname

删除本地分支
git branch -d branchname
强行删除本地分支【在分支未合并的状态下】
git branch -D branchname
删除远程分支
git push origin --delete [branchname]

撤销和删除操作

撤销工作区的修改
git checkout --filename
撤销添加到stage
git reset HEAD filename
回退版本
git reset --hard HEAD^【回退上个版本】
git reset --hard commit_id【根据commit回退版本】

删除本地仓库文件
git rm filename && git commit -m ‘message’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值