基本的Git命令摘要

基本的git命令摘要。

很难看到,因为它最初是为我制作的。



INIT

$ git init

在目录中创建一个存储库。

$ git init --bare

创建裸仓库

$ git init --shared

启用组写入权限。



添加

$ git add [filename]

索引文件和目录。

$ git add -A

添加工作树的内容,包括索引的所有更改。

$ git add -u

只有我已经承诺的文件被添加到索引。



承诺

$ git commit

提交文件添加到索引。

$ git commit -m “[comment]”

同时指定提交信息。

$ git commit -a

将更改的文件(不包括新的)添加到索引并提交。

$ git commit --amend

纠正最后一次提交。



状态

$ git status

它显示哪个文件与之前的提交相比有所变化。



日志

$ git log

参考提交日志。

$ git log --oneline

显示提交日志的前7位提交ID。

$ git log --decorate

指定提交日志的HEAD的位置。

$ git log --graph

在垂直图中显示提交日志。

$ git log --grep [filter]

显示提交日志中包含指定字符的提交。



DIFF

$ git diff

显示索引和工作树的区别。

$ git diff --cache

显示HEAD和索引之间的差异。

$ git diff [commit id 1] [commit id 2]

显示提交之间的差异。



结账

$ git checkout [commit id] [filename]

恢复提交的过去的文件。

$ git checkout [branch]

改变分支。

$ git checkout --ours [filename]

合并冲突时,指定信息并采用文件内容。

$ git checkout --theirs [filename]

与合并冲突时,指定底部并采用文件内容。



节目

$ git show

显示最新的提交内容。

$ git show [tagname]

指定标签并显示提交内容。



重置

$ git reset [commit id]

将索引设置为当前的HEAD状态。

$ git reset HEAD [filename]

从索引中取消文件。

$ git reset --hard [commit id]

将所有包含工作树的工作树还原到提交ID状态。

$ git reset --hard HEAD@{[number]}

返回到由git reflog确认的编号的状态。

$ git reset --hard ORIG_HEAD

返回到以前的状态。



RM

$ git rm [filename]

从工作树和索引中删除文件。

$ git rm --cache [filename]

删除索引文件。



MV

$ git mv [filename 1] [filename 2]

更改文件名(文件存在于索引和工作树中时)



还原

$ git revert [commit id]

取消提交ID的提交。



变基

$ git rebase -i [commit id]

提交从提交ID旧顺序出现,能够进行编辑,如更换提交消息和擦除线的提交提交消除,拾取到其他人的头部。

$ git rebase --abort

取消编辑以前的git rebase。

$ git rebase --continue

适应git rebase的变化。



克隆

$ git clone [repository PATH] [new repository PATH]

复制存储库。



$ git push [remote repository PATH] [branch]

将更改写入远程存储库。

$ git push [remote repository] --tags

将所有标签上传到远程存储库。

$ git push [remote repository] [tagname]

将指定的标签上传到远程存储库。

$ git push [remote repository] :[branch or tagname]

从远程存储库中删除指定的分支或标记。



$ git pull [remote repository PATH] [branch]

捕获远程存储库中的更改。



远程

$ git remote

列出远程存储库

$ git remote add [username] [remote repository PATH]

关联名称和远程存储库(添加远程存储库)。

$ git remote rename [remoterepository] [new name]

更改远程存储库的名称。

$ git remote show [remote repository]

查看远程存储库信息。

$ git remote prune [remote repository]

从本地删除从远程存储库中排除的分支。



$ git fetch [remote repository]

在远程存储库上添加最新信息。

$ git fetch --prune

在本地更新远程存储库的删除信息。



$ git branch &[new branch]

确认当前分支和创建一个新的分支。

$ git branch -a

检查所有分支。

$ git branch -r

检查远程分支。

$ git branch -d [branch]

删除分支。

$ git branch -m [branch] [new branchname]

更改分支的名称。

$ git branch --set-upstream [my branch] [other branch]

将您的分支与另一个用户的分支相关联。



合并

$ git merge [branch]

将当前分支与其他分支合并。



标签

$ git tag

显示标签列表。

$ git tag -n[number]@

显示标签及其信息的列表[指定行数](在没有行号规格的情况下为1行)。

$ git tag -l [filter]

用过滤器显示标签。

$ git tag [tagname]

将标签与当前提交ID相关联。

$ git tag [tagname] [commit id]

通过指定提交ID来关联标记。

$ git tag -a [tagname]

将消息标记与当前提交ID相关联。

$ git tag -d [tagname]

删除指定的标签。



$ git stash

保存当前状态。

$ git stash save “[message]”

用消息保存当前状态。

$ git stash list

显示已保存状态的列表。

$ git stash pop

恢复最新的保存状态。

$ git stash pop stash@{[numbar]}

指定号码并恢复保存的状态。

$ git stash apply

恢复最新的保存状态,同时保存列表中的保存状态。

$ git stash apply stash@{[number]}

恢复指定号码的保存状态,同时保存列表中的保存状态。

$ git stash drop stash@{[number]}

删除保存的状态。

$ git stash clear

删除所有保存的状态。



引用日志

$ git reflog

显示HEAD过去指向的提交列表。

$ git reflog [branch]

指定一个分支并显示HEAD过去指向的提交列表。



摘樱桃

$ git cherry-pick [commit id]

将另一个分支的提交复制到当前分支。



配置

$ git config -l

显示要使用的存储库的配置。

$ git config --global user.name [username]

用户名称设置。

$ git config --global user.email [email address]

邮件地址设置。

$ git config --global color.ui auto

颜色输出结果。

发表评论