git 基础命令速记

本文所有命令都是摘自《Git》,详细在线内容见[url]https://git-scm.com/book/zh/v2[/url].

git config # 查看或配置git
git init # 初始化仓库
git status # 查看仓库状态
git add file1 ... # 将文件添加到跟踪区或者把跟踪文件放到暂存区
git reset HEAD filename # 取消暂存文件
git checkout -- filename # 撤销尚未暂存的修改
git rm file1 ... # 从暂存区中移除文件,同时也从工作目录中删除
git rm --cached file # 仅从暂存区中移除文件
git commit -m "说明信息" # 正式提交更新修改信息
git commit -a # 跳过“git add”步骤
git commit --amend # 重新提交,同时会将暂存区中的文件也给提交。
git mv file_from file_to # 移动文件,改为对文件 file_to 跟踪
git clone 仓库地址 # 克隆远程仓库
git diff # 查看暂存前后的变化
git diff --cached/--staged # 查看已经暂存起来的变化
git log [-n] # 查看最近 n 次提交历史
git log -p # 查看提交的内容差异
git log --pretty=[oneline/format:"%h - %an, %ar : %s"] # 按指定格式输出提交历史

git remote # 列出已配置的远程仓库服务器的简写
git remote -v # 还会列出远程仓库对应的 url
git remote add shortname url # 添加一个远程仓库,同时指定一个简写以代表该 url
git fetch shortname/url # 拉取远程仓库数据(不会自动合并)
git pull repository # 拉取远程仓库数据(会尝试自动合并,更为常用)
git push repository branchName # 推送到远程仓库(不过要确保没有冲突)
git remote show repository # 查看远程仓库信息
git remote rename oldName newName # 重命名远程仓库
git remote rm repository # 移除远程仓库

git tag [argument] # 查看或者打各种标签
git push remoteRepo --tags # 推送所有标签到远程仓库(默认“git push”不会推送)
git config --global alias.aliasName command # 为命令定义别名

git branch branchName # 创建一个分支
git branch -d branchName # 删除分支
git log --decorate # 查看各个分支当前所指的对象
git checkout branchName # 切换分支
git checkout -b branchName # 创建并切换到该分支
git merge branchName # 将分支 branchName 与当前所在分支进行合并
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值