Git的概念及常用命令

一、概念

Git是一个分布式的版本控制工具,区别于集中式管理的SVN。

二、优势

  • 每个开发者都拥有自己的本地版本库,可以在本地任意修改代码、创建分支,不会影响到其他开发者的使用;

  • 所有版本信息均保存在.git目录下,完整克隆中心版本库;

  • 切换分支迅速,方便合并,合并速度快于SVN;

  • 分布式版本库,无单点故障。

三、常用命令

git init 初始化git仓库

git config --list 查看本地仓库配置信息

git config --global user.name "输入你的用户名"

git config --global user.email "输入你的邮箱"

git config --global --replace-all user.email "输入你的邮箱"

git config --global --replace-all user.name "输入你的用户名"

git branch 查看当前分支

git add 'filename' 添加文件到暂存区

git status 查看git仓库状态

git commit -a -m 'remark' 提交仓库变动到分支

git stash 将当前未提交的改动保存到堆栈中

git stash pop stash@{num} 恢复指定num的改动

git pull 拉取远程代码到本地分支

git push 推送本地代码到远程分支

git fetch 拉取远程所有分支代码到本地仓库

git reset --hard origin/master 拉取远程master分支代码强制覆盖到本地

git merge --no-ff 'branch' 合并某个分支到当前分支

git diff otherBranchName 和另一个分支进行比较(列出具体的差异)

git diff --name-only otherBranchName 和另一个分支进行比较(仅列出存在差异的文件名)

git diff HEAD^ 和当前分支的上一个commit比较(列出具体的差异)

git diff --name-only HEAD^ 和当前分支的上一个commit比较(仅列出存在差异的文件名)

git diff HEAD^ fileName 某个具体的文件和当前分支的上一个commit比较(列出具体的差异)

注:

HEAD 当前最新commit

HEAD^ 上一个commit

HEAD^^ 上上个commit

HEAD~N (N为整数) 前N个commit

也可以是具体的commitid值
原文地址:https://www.cnblogs.com/clivewang/p/9863749.html