Git 常用命令集锦

1. 安装后的初始化:

git config --global user.name "your name"
git config --global user.email "your email"
git config --global credential.helper store # 记录账户密码,免去每次都输入


2. 常规操作

    git init #初始化一 git 仓库
    git add "filename"    # 添加文件
    git rm --cached file # 从未提交的缓冲区删除文件(未受管理状态)
    git rm file    # 从版本库中删除
    git commit -m "本次提交的描述信息" #提交到本地仓库
    
    git log        # 查看历史记录(只包含提交)
    git reflog    # 查看操作日志(历史命令)
    git status    # 查看状态
    git diff        # 查看不同

3. 回退

    git reset --hard HEAD^ # 上一个版本号
    git reset --hard 指定的版本号 # 恢复到指定版本号


4. 撤销修改(就是会退到上一次 git commit 或 git add 时的状态)

    git checkout -- filename
    撤销修改包含撤销删除的文件

5. 远程仓库

    # 关联一个远程仓库
    git remote add origin https://github.com/***.git;
    # 推送至远程仓库的 master 分支
    git push -u origin master
    # 从远程仓库克隆
    git clone https://github.com/***.git

6. 分支

    git branch dev     # 创建分支
    git checkout dev        # 切换分支
    git checkout -b  dev2     # 创建并切换
    git branch    # 查看分支状态
    git merge dev    # 和 dev 分支合并
    git branch -d dev     # 删除 dev 分支

7. 标签

    git tag v1.0        # 给当前分支当前状态打标签
    git tag v0.9 f52c633    # 对特定的一次提交打标签
    git tag        # 查看所有标签
    git show v0.9    # 查看标签信息
    #  -a 标签名 -m 标签信息
    git tag -a v0.1 -m "version 0.1 released" 1094abd

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值