.git clone
克隆一个指定repo到本地。指定的repo可以是本地文件系统或者由HTTP或SSH指定的远程路径。
Clone repo located at
git configuser.name
针对当前repo配置用户名。使用--global 参数将配置全局用户名。
Define author name to be used for all commits in current repo. Devs commonly use --global flag to set config options for current user.
git add
将指定目录的所有修改加入到下一次 commit中。把
Stage all changes in
git commit -m
提交暂存区的修改,使用指定的
Commit the staged snapshot, but instead of launching a text editor, use
git status
显示哪些文件已被staged、未被staged以及未跟踪(untracked)。
List which files are staged, unstaged, and untracked.
git log
以缺省格式显示全部commit历史。更多自定义参数请参考后续部分。
Display the entire commit history using the default format. For customization see additional options.
GIT DIFF
git diff
比较工作区和暂存区的修改。
Show unstaged changes between your index and working directory.
git diff HEAD
比较工作区和上一次commit后的修改。
Show difference between working directory and last commit.
git diff --cached
比较暂存区和上一次commit后的修改。
Show difference between staged changes and last commit
UNDOING CHANGES
git revert
对指定
Create new commit that undoes all of the changes made in
git reset
将
Remove
REWRITING GIT HISTORY
git commit -m
将当前staged修改合并到最近一次的commit中。
Replace the last commit with the staged changes and last commit combined.
git merge
基于
Rebase the current branch onto
git rebase
基于
Show a log of changes to the local repository's HEAD.
git reflog
显示本地repo的所有commit日志。
Show a log of changes to the local repository's HEAD.
GIT BRANCHES
git branch
显示本地repo的所有分支。
List all of the branches in your repo.
git switch -c
创建并切换到一个新的名为
Create and switch to a new branch named
git merge
将指定
Merge
REMOTE REPOSITIONS
git remote add
添加一个新的远程连接。添加后可使用
Create a new connection to a remote repo. After adding a remote, you can use
git fetch
从指定
Fitches a specific
git pull
从指定
Fetch the specified remote's copy of current branch and immediately merge it into the local copy.
git push
将本地指定
Push the branch to
GIT CONFIG
git config -- global user.name
配置当前用户名,使用--global参数将针对当前系统登录用户生效。
Define the author name to be used for all commits by the current user.
git config -- global user.email
配置当前用户Email。
Define the author email to be used for all commits by the current user.
git config -- global alias.
配置一个git命令的快捷方式。例如:配置"alias.glog log --graph --online"使"git glog"相当于"git log --graph --online".
Create shortcut for a Git command. E.g. alias.glog "log --graph --online" will set "git glog" equivalent to "git log --graph --online".
git config -- system core.editor
配置文本编辑器,例如vi,在必要时自动打开此文本编辑器。
Set text editor used by commands for all users on the machine.
git config -- global --edit
打开当前用户的git全局配置并编辑。
Open the global configuration file in a text editor for manual editing.
GIT LOG
git log --limit
限制log的显示数量。例如:"git log -5"仅显示最新5条commit。
Limit number of commits by
git log --oneline
每行显示一条commit。
Condense each commit to a single line.
git log --author= "
按提交者名字搜索并显示commit。
Search for commits by a particular author.
git log --grep= "
按指定内容搜索并显示commit。
Search for commits with a commit message that matches
git log
显示指定范围的commit。范围参数可以是 commit ID, 分支名称、HEAD或任意相对位置。
Show commits that occur between
git log --hard
将当前分支回滚到指定
Same as previous, but resets both the staging area & working directory to match. Deletes uncommitted changes, and all commits after
git reset --hard
将当前分支回滚到指定
--graph flag draws a text based graph of commits on left side of commit msgs.
GIT RESET
git reset
移除所有暂存区的修改,但不会修改工作区。
Reset staging area to match most recent commit, but leave the working directory unchanged.
git reset --hard
移除所有暂存区的修改,并强制删除所有工作区的修改。
Reset staging area and working directory to match most recent commit and overwrites all changes in the working directory.
git reset
将当前分支回滚到指定
Move the current branch tip backward to
git reset --hard
将当前分支回滚到指定
Same as previous, but resets both the staging area & working directory to match. deletes uncommitted changes, and all commits after
GIT REBASE
git rebase -i
以交互模式对当前分支做rebase。
Interactively rebase current branch onto
GIT PULL
git pull --rebase
抓取所有远程分支,并以rebase模式并入本地repo而不是merge。
Fetch the remote's copy of current branch and rebases into the local copy. Uses git rebase instead of merge to integrate the branches.
GIT PUSH
git push
将本地分支推送到远程。不要使用--force参数,除非你完全明白此操作的后果。
Forces the git push even if it results in a non-fast-forward merge. Do not use the -- force flag unless you're absolutely sure you know what you're doing.
git push
使用push命令并不会自动将本地tag推送到远程。加上-tags参数会将所有本地tag推送到远程。
Tags aren't automatically pushed when you push a branch or use the --all flag. The --tags flag sends all of your local tags to the remote repo.