85个常用git命令
-
以下是常用的85个Git命令:
1. git init:在当前目录中初始化一个新的Git仓库。
2. git clone [url]:从远程仓库克隆一个副本到本地。
3. git add [file]:将指定文件添加到暂存区。
4. git commit -m [message]:提交所有暂存的文件,并添加一个描述信息。
5. git status:显示工作区和暂存区的状态。
6. git log:显示提交日志。
7. git diff:显示未暂存和未提交的改动。
8. git branch:显示本地分支列表。
9. git branch [branch]:创建一个新的本地分支。
10. git checkout [branch]:切换到指定的分支。
11. git merge [branch]:将指定分支合并到当前分支。
12. git remote:显示远程仓库列表。
13. git remote add [name] [url]:添加一个新的远程仓库。
14. git push [remote] [branch]:将当前分支推送到远程仓库。
15. git pull [remote] [branch]:从远程更新并合并到本地。
16. git fetch:从远程获取最新的提交,但不合并到当前分支。
17. git stash:将当前的改动保存到一个临时区域,以便切换到其他分支。
18. git reset [commit]:撤销指定的提交。
19. git revert [commit]:撤销指定的提交,并创建一个新的提交来反转改动。
20. git show [commit]:显示指定提交的详细信息。
21. git tag:显示标签列表。
22. git tag [name]:创建一个新的标签。
23. git checkout [tag]:切换到指定的标签。
24. git rebase [branch]:将当前分支的提交应用到指定分支的最后面。
25. git cherry-pick [commit]:将指定的提交应用到当前分支。
26. git config [–global] user.name [name]:设置用户名。
27. git config [–global] user.email [email]:设置用户邮箱。
28. git config [–global] color.ui true:开启彩色输出。
29. git config [–global] core.editor [editor]:设置默认文本编辑器。
30. git config [–global] alias.[alias] [command]:创建一个常用的命令别名。
31. git remote update:从远程仓库更新所有分支。
32. git remote show [remote]:显示远程仓库的详细信息。
33. git remote rename [old] [new]:将远程仓库重命名。
34. git remote remove [remote]:移除指定的远程仓库。
35. git branch -d [branch]:删除指定的本地分支。
36. git branch -r:显示远程分支列表。
37. git branch -vv:显示本地分支与远程分支的关联关系。
38. git checkout -b [branch]:创建一个新的分支,并切换到它。
39. git checkout -:切换到上一个分支。
40. git merge –no-ff [branch]:进行非快进式的合并。
41. git reset –hard [commit]:将当前分支重置到指定的提交。
42. git reset –soft [commit]:将当前分支重置到指定的提交,但保留改动。
43. git reflog:显示引用日志,包括HEAD和分支的所有移动。
44. git pull –rebase [remote] [branch]:从远程拉取并进行重新基准合并。
45. git stash save [message]:保存改动并添加描述信息。
46. git stash list:显示保存的改动列表。
47. git stash apply [stash]:应用保存的改动。
48. git stash drop [stash]:删除保存的改动。
49. git stash clear:删除所有保存的改动。
50. git push –force [remote] [branch]:强制推送到远程分支。
51. git clean -n:显示将要删除的未被跟踪的文件。
52. git clean -f:删除未被跟踪的文件。
53. git rebase -i [commit]:交互式合并提交。
54. git tag -a [name] -m [message] [commit]:为指定的提交创建一个带有描述信息的标签。
55. git tag -l:列出所有的标签。
56. git tag -d [name]:删除指定的标签。
57. git show [tag]:显示指定标签的详细信息。
58. git log –graph:以图形方式显示提交历史。
59. git log –author=[author]:按作者过滤提交历史。
60. git log –since=[date]:按日期过滤提交历史。
61. git log –oneline:以一行显示提交历史。
62. git log –stat:以简要统计方式显示提交历史。
63. git remote show [remote]:显示指定远程仓库的详细信息。
64. git remote update [remote]:从指定的远程仓库更新所有分支。
65. git remote prune [remote]:删除不在远程仓库的分支。
66. git config –global core.autocrlf [mode]:设置换行符的自动转换方式。
67. git config –global core.safecrlf [mode]:设置换行符的安全检查方式。
68. git config –global core.ignorecase [true/false]:设置文件名大小写敏感性。
69. git blame [file]:显示指定文件的每一行是由谁修改的。
70. git shortlog:按作者进行简要报告。
71. git archive [branch] -o [file]:将指定分支的文件打包。
72. git revert –no-commit [commit]..HEAD:撤销从指定提交到HEAD之间的改动。
73. git remote prune-origin:删除远程仓库中不再存在的分支。
74. git clean -xdf:删除未被跟踪的文件和目录。
75. git fsck:检查仓库中的问题。
76. git grep [pattern]:在仓库中搜索指定模式。
77. git cherry-pick –abort:放弃当前的cherry-pick操作。
78. git diff [branch1] [branch2]:比较两个分支之间的差异。
79. git branch -a:显示所有分支,包括远程分支。
80. git checkout — [file]:撤销对文件的改动。
81. git reset HEAD [file]:将文件从暂存区移除。
82. git revert –abort:放弃当前的revert操作。
83. git commit –amend:修改最后一次提交的描述信息。
84. git tag -m [message] [tag] [commit]:为指定的提交创建一个带有描述信息的轻量标签。
85. git config –global core.excludesfile [file]:设置全局的Git忽略文件。这些是常用的Git命令,覆盖了Git的基本操作和一些高级功能,希望对你有帮助!
2年前 -
以下是一份常用的85个Git命令:
1. git init:初始化一个新的Git仓库。
2. git clone [url]:克隆一个远程仓库到本地。
3. git add [file]:将文件添加到暂存区。
4. git commit -m [message]:提交暂存区的文件到本地仓库,并添加提交信息。
5. git status:查看当前仓库的状态。
6. git diff:查看文件的修改内容。
7. git branch:查看当前仓库的分支。
8. git checkout [branch]:切换到指定的分支。
9. git checkout -b [branch]:创建并切换到一个新的分支。
10. git merge [branch]:合并指定分支到当前分支。
11. git remote:查看当前仓库的远程仓库。
12. git remote add [name] [url]:添加一个远程仓库。
13. git push [remote] [branch]:将本地仓库的更改推送到远程仓库。
14. git pull [remote] [branch]:从远程仓库拉取最新的更改。
15. git fetch:从远程仓库获取最新的提交。
16. git log:查看提交日志。
17. git revert [commit]:撤销指定的提交。
18. git reset [commit]:撤销指定的提交,并将更改移动到暂存区。
19. git stash:将当前的工作目录保存到一个临时存储区。
20. git stash apply:将之前保存的工作目录恢复到当前分支。
21. git cherry-pick [commit]:选择一个或多个提交,并将其应用到当前分支。
22. git tag [name]:创建一个标签,并指定一个版本号。
23. git show [commit]:显示一个提交的详细信息。
24. git config –global user.name [name]:配置全局用户名。
25. git config –global user.email [email]:配置全局用户邮箱。
26. git ignore:创建一个.gitignore文件,并添加忽略规则。
27. git blame [file]:显示文件的修改历史和作者信息。
28. git branch -d [branch]:删除指定的分支。
29. git reset –hard [commit]:将当前分支的HEAD指针重置为指定的提交。
30. git rebase [branch]:将当前分支的提交应用到指定的分支上。
31. git pull –rebase [remote] [branch]:从远程仓库拉取最新的更改,并将本地的提交重新应用在上面。
32. git config –global alias.[alias-name] [command]:创建一个git别名。
33. git clean -f:清除工作目录中未跟踪的文件。
34. git blame -L [start],[end] [file]:仅显示指定范围内的文件的修改历史和作者信息。
35. git checkout — [file]:撤销对文件的修改,恢复到最近的提交状态。
36. git reset HEAD [file]:从暂存区撤销对文件的修改。
37. git revert -n [commit]:撤销指定的提交,但不创建新的提交。
38. git log –author=[author]:查看指定作者的提交日志。
39. git log –before=[date]:查看指定日期之前的提交日志。
40. git log –after=[date]:查看指定日期之后的提交日志。
41. git log -S [string]:查看包含特定字符串的提交日志。
42. git log –grep [pattern]:查看包含特定模式的提交日志。
43. git log –oneline:以单行的方式显示提交日志。
44. git log –graph:以图形化的方式显示提交日志。
45. git remote -v:查看当前仓库的详细远程仓库信息。
46. git remote show [remote]:显示指定远程仓库的详细信息。
47. git push –tags:将本地的标签推送到远程仓库。
48. git tag -a [name] -m [message]:创建一个带注释的标签。
49. git show-ref [tagname]:显示指定标签的引用。
50. git show-branch:显示所有分支的提交历史。
51. git blame -C [file]:显示文件的修改历史和作者信息,同时查找内容的复制来源。
52. git blame -M [file]:显示文件的修改历史和作者信息,同时查找内容的重命名来源。
53. git blame -L [start],[end] -C -M [file]:仅显示指定范围内的文件的修改历史和作者信息,同时查找内容的复制和重命名来源。
54. git revert –no-commit [commit]:撤销指定的提交,但不创建新的提交,并将更改直接应用到工作目录。
55. git revert –no-edit [commit]:撤销指定的提交,但不创建新的提交,并使用原提交的提交信息。
56. git branch -m [new-name]:重命名当前分支。
57. git branch -a:查看所有分支,包括远程分支。
58. git checkout –orphan [branch]:创建一个没有历史记录的新分支。
59. git checkout -p [file]:交互式地选择并撤销对文件的部分修改。
60. git stash drop:删除最近的保存的工作目录。
61. git stash list:列出所有保存的工作目录。
62. git stash pop:将最近的保存的工作目录恢复到当前分支,并删除保存的工作目录。
63. git stash branch [branchname]:从保存的工作目录创建一个新分支。
64. git pull –autosquash [remote] [branch]:从远程仓库拉取最新的更改,并自动进行变基和合并。
65. git rebase -i [branch]:交互式地变基当前分支到指定分支。
66. git rebase –abort:放弃变基操作,并恢复到变基之前的状态。
67. git reset –hard HEAD~[num]:将当前分支的HEAD指针重置到前[num]个提交之前,并清空工作目录。
68. git reset –soft HEAD~[num]:将当前分支的HEAD指针重置到前[num]个提交之前,并保留更改在暂存区。
69. git reset branch -f [commit]:将指定分支的HEAD指针重置为指定的提交。
70. git reset –mixed [commit]:将HEAD指针重置为指定提交,并将更改移动到工作目录。
71. git reflog:查看HEAD和分支的引用日志。
72. git cherry-pick –abort:放弃cherry-pick操作,并恢复到cherry-pick之前的状态。
73. git cherry-pick –continue:继续cherry-pick操作,并应用下一个提交。
74. git revert –no-edit –no-commit [commit]:撤销指定提交的更改,并应用到当前分支。
75. git revert –mainline [commit]:在合并冲突时,选择指定提交作为主分支。
76. git bisect start [bad] [good]:启动二分查找,指定一个不好的和一个好的提交作为开始和结束。
77. git bisect bad:标记当前提交为有问题的提交。
78. git bisect good:标记当前提交为好的提交。
79. git bisect reset:结束二分查找,并恢复到查找之前的状态。
80. git clean -f -d:清除工作目录中未跟踪的文件和目录。
81. git stash clear:清除所有保存的工作目录。
82. git stash branch [branchname] [stash]:从指定的保存的工作目录创建一个新分支。
83. git clean -n:显示将被清除的文件和目录的列表,但不真正执行。
84. git clean -x:清除工作目录中未跟踪的文件和目录,包括忽略文件中指定的文件和目录。
85. git clean -i:交互式地选择并清除工作目录中未跟踪的文件和目录。2年前 -
介绍常用的Git命令,以帮助使用者更好地进行版本控制和协同开发。
1. git init
该命令用于在当前目录中初始化一个新的Git仓库。2. git clone [url]
将远程仓库的内容克隆到本地。3. git add [file]
将文件添加到暂存区。4. git status
查看文件状态,显示已修改但未提交的文件。5. git commit -m “[message]”
提交更改,并添加描述信息。6. git diff
显示所有未添加到暂存区的更改。7. git branch
列出本地分支。8. git checkout [branch name]
切换到指定分支。9. git merge [branch name]
将指定分支与当前分支合并。10. git pull origin [branch name]
从远程仓库拉取最新代码。11. git push origin [branch name]
推送本地提交到远程仓库。12. git log
显示提交日志。13. git revert [commit]
撤销指定提交。14. git reset [commit]
撤销指定提交,并将更改保存在工作区。15. git rm [file]
从Git中删除文件。16. git remote add origin [url]
将远程仓库添加到当前仓库。17. git fetch
从远程仓库获取最新内容,但不自动合并。18. git stash
将当前工作区的更改保存到栈中,并清空当前工作区。19. git cherry-pick [commit]
选择指定提交,并将其应用到当前分支。20. git rebase [branch]
将当前分支变基到指定分支。21. git tag [tag name]
为当前提交打标签。22. git diff [commit] [commit]
显示两个提交之间的差异。23. git remote -v
显示远程仓库的详细信息。24. git remote remove [remote name]
删除指定远程仓库。25. git remote rename [old name] [new name]
重命名指定的远程仓库。26. git log –pretty=format:”[%h] %an %ar : %s”
以特定的格式显示提交日志。27. git log –grep=”[pattern]”
搜索提交信息中匹配指定模式的提交。28. git config –global user.name [name]
设置全局账户用户名。29. git config –global user.email [email]
设置全局账户邮箱。30. git branch -d [branch name]
删除指定分支。31. git checkout -b [branch name]
创建并切换到新的分支。32. git fetch origin [branch name]
从远程仓库获取最新内容,将其合并到指定分支。33. git branch -m [old name] [new name]
重命名指定分支。34. git checkout — [file]
撤销对文件的更改。35. git commit –amend
修改最近一次的提交。36. git push –force origin [branch name]
强制推送到远程仓库。37. git pull –rebase origin [branch name]
从远程仓库拉取最新代码,并将当前分支的提交变基到拉取的代码之上。38. git stash apply
恢复最近一次保存在栈中的工作区。39. git clean -fd
删除未被追踪的文件和文件夹。40. git show [commit]
显示指定提交的详细信息与更改。41. git reflog
显示引用日志,包括分支和HEAD的变更历史。42. git bisect start
启动二分查找,用于定位引入问题的提交。43. git remote update
更新远程仓库的引用。44. git revert –no-commit [commit]
撤销指定提交的更改,并将结果保存在暂存区。45. git rm –cached [file]
从Git中删除文件,但保留本地文件。46. git stash drop
丢弃最近一次保存在栈中的工作区。47. git p4 clone [depot]
从Perforce迁移到Git。48. git cherry-pick –abort
放弃正在进行的cherry-pick操作。49. git diff [branch1]…[branch2]
显示两个分支之间的差异。50. git merge –abort
放弃正在进行的合并操作。51. git rebase –abort
放弃正在进行的变基操作。52. git branch -a
列出所有分支,包括远程分支。53. git tag -l
列出所有标签。54. git config –global core.autocrlf true
设置Git自动处理换行符。55. git revert –no-edit
撤销指定提交时不打开编辑器。56. git remote show [remote name]
显示指定远程仓库的详细信息。57. git branch -v
以列表形式显示分支的最新提交。58. git cherry-pick –continue
继续进行正在进行的cherry-pick操作。59. git diff –cached
显示已添加到暂存区的更改。60. git checkout -p
选择性地还原文件的更改,而不是整个文件。61. git commit –amend –no-edit
修改最近一次提交的内容,但不修改提交信息。62. git push origin –delete [branch name]
删除远程仓库的指定分支。63. git stash save [message]
将当前工作区的更改保存到栈中,并给保存的更改添加描述信息。64. git fetch –all
从所有远程仓库获取最新内容。65. git revert –no-commit HEAD~[n]
撤销前n个提交,并将结果保存在暂存区。66. git rm -r [directory]
删除指定目录。67. git log –since=”[date]”
显示指定日期之后的提交。68. git diff [commit]…HEAD
显示指定提交与当前提交之间的差异。69. git add -A
将所有更改添加到暂存区。70. git commit –no-verify
跳过提交的钩子验证。71. git push –tags
推送所有标签到远程仓库。72. git fetch –prune
从远程仓库获取最新内容,并删除本地已删除的远程分支。73. git reflog show [refname]
显示指定引用的变更历史。74. git revert –no-commit HEAD~[n]..HEAD
撤销前n个提交到最新提交之间的更改,并将结果保存在暂存区。75. git stash drop [stash id]
丢弃指定的工作区。76. git diff [branch1]…[branch2] [path]
显示两个分支之间指定路径下的差异。77. git merge [branch1]…[branch2]
将多个分支的更改合并到当前分支。78. git cherry-pick -m [parent]
合并指定提交的更改。79. git rm –cached -r [directory]
从Git中删除指定目录,但保留本地文件。80. git log –grep=”[pattern]” –author=”[author name]”
搜索指定作者提交信息中匹配指定模式的提交。81. git diff –name-only [commit] [commit]
显示两个提交之间的差异,并只显示文件名。82. git checkout –ours [file]
在合并冲突时选择保留当前分支的更改。83. git commit –amend –author=”[author name]
”
修改最近一次提交的作者信息。84. git push -u origin [branch name]
推送本地分支到远程仓库,并将本地分支与远程分支关联。85. git stash apply [stash id]
恢复指定的工作区。2年前