我经常使用的 Git 经常使用命令

Git 推荐阅读

查看

查看全部commit的历史

git log

查看某个文件的提交记录

git log -p <filename>

查看某人的提交记录

git log --stat --author=someone

查看某次commit的修改内容

git show <commit-hash-id>

查看最近2次的更新内容

git log -p -2

对比

查看修改以后尚未暂存起来的变化内容

git diff

查看已经暂存起来的文件(staged)和上次提交时的快照之间(HEAD)的差别

git diff --staged

查看工做版本(Working tree)和HEAD的差异

git diff HEAD

其它

撤销暂存区的文件

即对撤销使用过 git add 命令的文件,撤销其 git add 操做git

git reset HEAD test.html

版本回退

  1. git log --pretty=oneline 能够查看更为清晰的 logwindows

  2. HEAD 表示当前版本,HEAD^ 表示上一个版本,HEAD^^ 表示上上一个版本,再往上 100 个版本则用 HEAD~100 表示bash

  • Git容许咱们在版本的历史之间穿梭,使用命令 git reset --hard commit_idcode

  • 穿梭前,用 git log 能够查看提交历史,以便肯定要回退到哪一个版本。htm

  • 要重返将来,用 git reflog 查看命令历史,以便肯定要回到将来的哪一个版本。教程

git clone 指定分支

git clone -b <branch name> [remote repository address]

设置/查看用户信息

设置用户信息

git config --global user.name "your name"
git config --global user.email "your email"

查看用户信息

git config user.name
git config user.email

或者rem

git config --global -l

每次提交代码都要输入用户名和密码的解决办法

.gitconfig 文件里面会有你先前配好的 nameemail,只需添加下面代码便可get

[credential]
     helper = store

.gitconfig 文件路径:hash

  • windows 系统默认状况: C:\Users\Administrator 目录

  • Linux系统:~/.gitconfig

查看配置信息

list 能够简写为 l

查看git 设置列表信息(包含用户名,用户邮箱,和是否保存密码)

git config --global --list

查看仓库级配置:

git config --local -l

查看全局级配置:

git config --global -l

查看系统级配置:

git config --system -l

积累、整理中...

相关文章
相关标签/搜索