git 基础命令速记

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

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 与当前所在分支进行合并

猜你喜欢

转载自aisxyz.iteye.com/blog/2377561
今日推荐