Git的常用命令

Git的常用命令

### 普通命令

git config --list  属性列表

git config --global <property-name> <property-value>  设置属性
eg: git config --global user.name "code_gzy"

git init 初始化本地仓库

git clone <url>  克隆远程仓库
eg: git clone https://gitee.com/code-gzy/ssm.git

git status
git status -s  查看文件状态

git add <file-name>  将文件添加到暂存区
eg: git add hello.txt

git reset Head <file-name>  将文件切换回未跟踪状态
eg: git reset Head hello.txt

git commit -m <log-message>  将暂存区的文件提交到本地仓库
git commit -a -m <log-message>	将文件提交到本地仓库(-a 是先执行add)
eg: git commit -m 'init hello.txt'

git rm <file-name>  删除文件进入暂存区,提交就会在本地仓库中也删除 (若:在文件夹中直接删除后,要add一下,再提交,本地仓库的文件才会删除)
eg: git rm hello.txt

git log 查看日志

git remote
git remote -v
git remote show <remote-name>	查看远程仓库


git remote add <remote-name> url 	添加远程仓库
eg: git remote add myrepo https://gitee.com/code-gzy/ssm.git

git remote rm <remote-name>  移除远程仓库
eg: git remote rm myrepo

git fetch  从远程仓库抓取但是不会自动合并(合并通过git merge '<remote-name>/<branch-name>')
eg: git fetch    ->    git merge origin/master

git pull <remote-name> <branch-name>  从远程仓库拉取仓库(若本地仓库存在其他文件则需要加参数 --allow-unrelated-histories)
eg: git pull origin master

git push <remote-name>  <branch-name>  将本地仓库推送到远程仓库
eg: git push origin master


### 分支命令

git branch 查看本地仓库分支

git branch -r  查看远程仓库分支

git branch -a  查看本地仓库和远程仓库所有分支

git branch <branch-name>	创建分支
eg: git branch b1

git checkout <branch-name>    切换分支
eg: git checkout b1

git push <remote-name> <branch-name>	推送分支到远程仓库
eg: git push origin b1

git merge <branch-name>	 合并分支		如果冲突,则在冲突文件中修改一下即可,再add和commit一下
eg: git merge b1

git branch -d <branch-name>	删除本地仓库的某条分支(-d删除不了,换-D)

git push <remote-name> -d <branch-name>	  删除远程仓库的某条分支


### 标签命令

git tag	查看标签

git tag <tag-name>  创建标签
eg: git tag v1.0

git push <remote-name> <tag-name>  将标签推送到远程仓库
eg: git push origin v1.0

git tag -d <tag-name>	删除本地仓库标签名
eg: git tag -d v1.0

git push <remote-name> :refs/tags/<tag-name> 	删除远程仓库便签名
eg: git push origin :refs/tags/v1.0
git pull --rebase origin master		本地代码目录中没有README.md,推送错误,则使用这个命令合并,再推送
posted @ 2021-06-01 10:46  code-G  阅读(44)  评论(0编辑  收藏  举报