git常用命令

1.新建代码

在当前目录新建一个Git代码库
git init
新建一个目录,将其初始化为Git代码库
git init [project-name]
下载一个项目和它的整个代码历史
git clone [url]

 2.增加删除文件

添加指定文件到暂存区

git add [file1] [file2] ...

添加当前目录的所有文件到暂存区

git add .

删除工作区文件,并且将这次删除放入暂存区

git rm [file1] [file2] ...

改名文件,并且将这个改名放入暂存区

git mv [file-original] [file-renamed]

3.代码提交

提交暂存区到仓库区

git commit -m [message]

提交暂存区的指定文件到仓库区

git commit [file1] [file2] ... -m [message]

使用一次新的commit,替代上一次提交,如果代码没有任何新变化,则用来改写上一次commit的提交信息

 git commit --amend -m [message]

重做上一次commit,并包括指定文件的新变化

git commit --amend   ...

4.分支

列出所有本地分支

 git branch

列出所有远程分支

git branch -r

列出所有本地分支和远程分支

git branch -a

新建一个分支,但依然停留在当前分支

 git branch [branch-name]

新建一个分支,并切换到该分支

 git checkout -b [branch]

切换到指定分支,并更新工作区

git checkout [branch-name]

合并指定分支到当前分支

git merge [branch]

删除分支

git branch -d [branch-name]

删除远程分支

git push origin --delete 
git branch -dr

5.标签

列出所有tag

git tag

查看tag信息

git show [tag]

提交指定tag

git push [remote] [tag]

6.查看所有信息

显示有变更的文件

git status

显示当前分支的版本历史

 git log

显示commit历史,以及每次commit发生变更的文件

 git log --stat

显示指定文件是什么人在什么时间修改过

 git blame [file]

显示暂存区和工作区的差异

 git diff

显示当前分支的最近几次提交

git reflog

7.远程同步

显示所有远程仓库

 git remote -v

增加一个新的远程仓库,并命名

 git remote add [shortname] [url]

上传本地指定分支到远程仓库

git push [remote] [branch]

恢复暂存区的指定文件到工作区

git checkout [file]

重置暂存区的指定文件,与上一次commit保持一致,但工作区不变

git reset [file]

 

posted @ 2023-04-25 15:41  企业级理解  阅读(8)  评论(0编辑  收藏  举报