Git基本常用命令

1.# 在当前目录新建一个Git代码库                               git init
2.# 新建一个目录,将其初始化为Git代码库                git init [project-name]
3.# 下载一个项目和它的整个代码历史                        git clone [url]
4.# 显示当前的Git配置                                                git config --list
5.# 编辑Git配置文件                                                    git config -e [--global]
6.# 设置提交代码时的用户信息                                   git config [--global] user.name "[name]"    

                                                                                     git config [--global] user.email "[email address]"
7.# 添加指定文件到暂存区                                            git add [file1] [file2] ...
8.# 添加指定目录到暂存区,包括子目录                        git add [dir]
9.# 添加当前目录的所有文件到暂存区                          git add .
10.# 添加每个变化前,都会要求确认                           git add -p
11. 删除工作区文件,并且将这次删除放入暂存区       git rm [file1] [file2] ...
12.停止追踪指定文件,但该文件会保留在工作区        git rm --cached [file]
13.改名文件,并且将这个改名放入暂存区                   git mv [file-original] [file-renamed]
14. 提交暂存区到仓库区                                               git commit -m [message]
15.提交暂存区的指定文件到仓库区                             git commit [file1] [file2] ... -m [message]
16.提交工作区自上次commit之后的变化,直接到仓库区 git commit -a
17.提交时显示所有diff信息                                    git commit -v
18.使用一次新的commit,替代上一次提交                git commit --amend -m [message]
19. 重做上一次commit,并包括指定文件的新变化    git commit --amend [file1] [file2] ...
20.列出所有本地分支                git branch
21.列出所有远程分支                git branch -r
22. 列出所有本地分支和远程分支            git branch -a
23.新建一个分支,但依然停留在当前分支        git branch [branch-name]
24.新建一个分支,并切换到该分支        git checkout -b [branch]
25.新建一个分支,指向指定commit        git branch [branch] [commit]
26.新建一个分支,与指定的远程分支建立追踪关系    git branch --track [branch] [remote-branch]
27.切换到指定分支,并更新工作区        git checkout [branch-name]
28.切换到上一个分支                git checkout -
29.建立追踪关系,在现有分支与指定的远程分支之间    git branch --set-upstream [branch] [remote-branch]
30.合并指定分支到当前分支            git merge [branch]
31.选择一个commit,合并进当前分支        git cherry-pick [commit]
32.删除分支                git branch -d [branch-name]
33.删除远程分支                git push origin --delete [branch-name] / git branch -dr [remote/branch]
34.列出所有tag                git tag
35.新建一个tag在当前commit            git tag [tag]
36.新建一个tag在指定commit            git tag [tag] [commit]
37.删除本地tag                git tag -d [tag]
38.删除远程tag                git push origin :refs/tags/[tagName]
39.查看tag信息                git show [tag]
40.提交指定tag                git push [remote] [tag]
41.提交所有tag                git push [remote] --tags
42. 新建一个分支,指向某个tag            git checkout -b [branch] [tag]
43.显示有变更的文件                git status
44.显示当前分支的版本历史            git log
45.显示commit历史,以及每次commit发生变更的文件    git log --stat
46.搜索提交历史,根据关键词             git log -S [keyword]
47.显示某个commit之后的所有变动,每个commit占据一行  git log [tag] HEAD --pretty=format:%s
48.显示某个commit之后的所有变动,其"提交说明"必须符合搜索条件  git log [tag] HEAD --grep feature
49. 显示某个文件的版本历史,包括文件改名     git log --follow [file] / git whatchanged [file]
50.显示指定文件相关的每一次diff        git log -p [file]
51.显示过去5次提交                git log -5 --pretty --oneline
52.显示所有提交过的用户,按提交次数排序        git shortlog -sn
53.显示指定文件是什么人在什么时间修改过        git blame [file]
54.显示暂存区和工作区的差异            git diff
55.显示暂存区和上一个commit的差异        git diff --cached [file]
56.显示工作区与当前分支最新commit之间的差异    git diff HEAD
57.显示两次提交之间的差异            git diff [first-branch]...[second-branch]
58. 显示某次提交的元数据和内容变化        git show [commit]
59.显示某次提交发生变化的文件            git show --name-only [commit]
60.显示某次提交时,某个文件的内容        git show [commit]:[filename]
61.显示当前分支的最近几次提交            git reflog
62.下载远程仓库的所有变动            git fetch [remote]
63. 显示所有远程仓库                git remote -v
64.显示某个远程仓库的信息            git remote show [remote]
65.增加一个新的远程仓库,并命名        git remote add [shortname] [url]
66.取回远程仓库的变化,并与本地分支合并        git pull [remote] [branch]
67.上传本地指定分支到远程仓库              git push [remote] [branch]
68.强行推送当前分支到远程仓库,即使有冲突    git push [remote] --force
69.推送所有分支到远程仓库            git push [remote] --all
70.恢复暂存区的指定文件到工作区        git checkout [file]
71.恢复某个commit的指定文件到暂存区和工作区    git checkout [commit] [file]
72.恢复暂存区的所有文件到工作区        git checkout .
73.重置暂存区的指定文件,与上一次commit保持一致,但工作区不变 git reset [file]
74.重置暂存区与工作区,与上一次commit保持一致    git reset --hard
75.重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变 git reset [commit]
76.生成一个可供发布的压缩包            git archive

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值