Git的100条命令及说明

1、git init

初始化一个Git仓库

2、git clone [url]

克隆一个远程Git仓库到本地

3、git add [file]

添加文件到暂存区

4、git add .

添加所有改动的文件到暂存区

5、git commit -m "message"

提交暂存区的文件到本地仓库

6、git status

查看工作区和暂存区的状态

7、git diff

查看修改前后的差异

8、git log

查看提交历史

9、git branch

查看本地分支列表

10、git branch [branch-name]

创建新的本地分支

11、git branch -d [branch-name]

删除本地分支

12、git checkout [branch-name]

切换到指定分支

13、git merge [branch-name]

合并指定分支到当前分支

14、git remote

查看远程仓库列表

15、git remote add [remote-name] [url]

添加远程仓库

16、git push [remote-name] [branch-name]

推送本地分支到远程仓库

17、git pull [remote-name] [branch-name]

从远程仓库拉取最新代码

18、git fetch [remote-name]

从远程仓库获取最新代码,但不合并到本地分支

19、git stash

暂存当前修改的内容

20、git stash apply

恢复暂存的修改内容

21、git stash drop

删除暂存的修改内容

22、git tag

查看本地标签列表

23、git tag [tag-name]

创建新的本地标签

24、git tag -d [tag-name]

删除本地标签

25、git push [remote-name] --tags

推送所有本地标签到远程仓库

26、git show [commit-hash]

查看指定提交的详细信息

27、git blame [file]

查看文件每一行的修改历史

28、git reset [commit-hash]

撤销指定提交并删除后续提交

29、git reset HEAD [file]

将指定文件从暂存区移除

30、git revert [commit-hash]

撤销指定提交,但不删除后续提交

31、git cherry-pick [commit-hash]

选择指定提交并应用到当前分支

32、git rebase [branch-name]

将当前分支的修改应用到指定分支

33、git bisect

通过二分法查找导致错误的提交

34、git grep [keyword]

在版本库中查找包含关键字的文件和内容

35、git log --author=[author-name]

查看指定作者的提交历史

36、git log --since=[date]

查看指定日期之后的提交历史

37、git log --until=[date]

查看指定日期之前的提交历史

38、git shortlog

查看提交日志的简略信息

39、git blame -L [line-number],[line-number] [file]

查看文件指定行的修改历史

40、git remote show [remote-name]

查看远程仓库的详细信息

41、git push -u [remote-name] [branch-name]

推送本地分支到远程仓库,并建立跟踪关系

42、git pull --rebase [remote-name] [branch-name]

从远程仓库拉取最新代码并进行变基操作

43、git log --pretty=format:"%h - %an, %ar : %s"

自定义提交历史的输出格式

44、git blame -M [file]

查找文件中移动的行,并显示移动前的作者和提交信息

45、git cherry-pick -n [commit-hash]

只选择指定提交的修改内容,而不是整个提交

46、git diff [commit1] [commit2]

比较两个提交之间的差异

47、git branch -m [old-branch-name] [new-branch-name]

将本地分支重命名

48、git for-each-ref

显示所有标签和分支的详细信息

49、git bisect start

开始二分查找错误的提交

50、git bisect bad

标记当前版本为错误的版本

51、git bisect good [commit-hash]

标记指定提交为正确的版本

52、git bisect reset

结束二分查找并返回到当前分支

53、git show-branch

显示本地分支之间的关系

54、git filter-branch

对整个仓库进行过滤和重写历史

55、git blame -C [file]

查找文件中复制和移动的行,并显示复制或移动前的作者和提交信息

56、git cherry-pick -e [commit-hash]

打开编辑器以修改提交信息,而不是使用默认的提交信息

57、git diff --cached

比较暂存区和最后一次提交之间的差异

58、git blame -L [start-line],[end-line] [file]

查找文件的指定行范围内的修改历史

59、git ls-files

列出版本库中所有的文件

60、git add -p

交互式添加文件到暂存区

61、git cherry-pick --no-commit [commit-hash]

将指定提交的修改内容应用到当前分支,但不进行提交

62、git rebase -i [commit-hash]

交互式变基操作

63、git submodule

管理子模块

64、git stash save "message"

将修改内容暂存并添加注释

65、git stash list

列出所有暂存的修改内容

66、git stash pop

恢复并删除最近暂存的修改内容

67、git stash apply stash@{n}

恢复指定序号的暂存的修改内容

68、git stash drop stash@{n}

删除指定序号的暂存的修改内容

69、git stash clear

删除所有暂存的修改内容

70、git blame -L '/regex/' [file]

查找文件中匹配正则表达式的行,并显示修改历史

71、git ls-remote

显示远程仓库的引用

72、git push [remote-name] :[branch-name]

删除远程分支

73、git log --graph --oneline --decorate

显示提交历史的分支和标签信息

74、git push [remote-name] HEAD

推送当前分支到远程仓库

75、git submodule update --init

初始化子模块

76、git submodule update

更新子模块

77、git stash branch [new-branch-name]

从最近的暂存内容创建新的分支

78、git rev-parse [commit-hash]

显示指定提交的哈希值

79、git commit --amend

修改最后一次提交的信息

80、git bisect visualize

显示二分查找的结果

81、git bisect run [script]

运行脚本,自动标记版本是否有错误

82、git blame -C -C [file]

查找文件中复制、移动和重命名的行,并显示修改历史

83、git merge --squash [branch-name]

将指定分支的修改内容合并到当前分支,但不提交

84、git config

配置Git

85、git mv [old-file-name] [new-file-name]

移动或重命名文件

86、git cherry-pick -x [commit-hash]

打印出应用指定提交的详细信息

87、git rebase --interactive HEAD\~[n]

对最近的n次提交进行交互式变基操作

88、git stash save -u "message"

暂存所有修改的文件,包括未跟踪的文件,并添加注释

89、git blame -C -C -M [file]

查找文件中复制、移动、重命名和修改的行,并显示修改历史

90、git pull --rebase=preserve

从远程仓库拉取代码并保留本地修改

91、git checkout -b [branch-name] [commit-hash]

创建新的分支并切换到指定提交的状态

92、git rev-list --all --count

显示版本库中提交的总数

93、git log --pretty=format:"%h %s" --graph

显示提交历史的图形化信息

94、git merge --no-ff [branch-name]

将指定分支的修改内容合并到当前分支,并创建一个新的提交

95、git rebase --onto [new-base] [old-base] [branch-name]

将指定分支从旧的基础变为新的基础

96、git cherry-pick -S [commit-hash]

签名应用指定提交的修改内容

97、git revert --no-commit [commit-hash]

撤销指定提交的修改内容,但不进行提交

98、git blame -C -C -C [file]

查找文件中复制、移动、重命名、修改和合并的行,并显示修改历史

99、git stash save -a "message"

暂存所有修改的文件,包括未跟踪和忽略的文件,并添加注释

100、git log --since="1 week ago" --author="[author-name]"

查看指定作者在一周内的提交历史。