git常用命令

作者: oryxtc | 来源:发表于2017-10-23 16:57 被阅读11次

获取Git的升级

git clone git://git.kernel.org/pub/scm/git/git.git

列出所有能找到的配置

git config --list

检查某一项配置

git config <key>

获取Git命令的使用手册

git help <verb>
git <verb> --help
man git-<verb>

在现有目录中初始化仓库

git init

克隆现有的仓库

git clone [url] [mylibrary]

检查当前文件状态

git status

添加内容到下一次提交中

git add <file>

查看尚未暂存的文件更新了哪些部分

git diff

查看已暂存的将要添加到下次提交里的内容

git diff --cached

提交更新

git commit -m <"msg">

跳过使用暂存区域

git commit -a -m [msg]

移除文件

git rm

强制移除已放到暂存区域的文件

git rm -f

想让文件保留在磁盘,但是并不想让 Git 继续跟踪

git rm --cached <file>

移动文件(重命名文件)

git mv

查看提交历史

git log [-p] [-num] [--stat]

重新提交

git commit --amend

取消暂存文件

git reset HEAD <file>

撤消对文件的修改

git checkout -- <file>

远程仓库使用的简写与其对应的URL

git remote -v

添加远程仓库

git remote add <shortname> <url>

从远程仓库中抓取与拉取

git fetch [remote-name]

推送到远程仓库

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

查看远程仓库

git remote show [remote-name]

远程仓库重命名

git remote rename [remote-name] [new-remote-name]

远程仓库删除

git remote rm [remote-name]

列出标签

git tag

创建附注标签

git tag -a [tagname] -m [msg]

创建轻量标签

git tag [tagname]

后期打标签

git tag -a [tagname] <key>

检出标签

git checkout -b [branchname] [tagname]

创建别名

git config --global [alias.alias-name] [command]

分支创建

git branch [branc-name]

分支切换

git checkout [branch-name]

删除本地分支

git branch -d [branch-name]

列出所有分支

git branch

推送分支至远程

git push (remote) (branch)

删除远程分支

git push (remote) --delete (branch)

变基

git rebase [basebranch]

将指定分支变基到目标分支

git rebase [basebranch] [topicbranch]

取出 client 分支,找出处于 client 分支和 server 分支的共同祖先之后的修改,然后把它们在 master 分支上重放一遍

git rebase --onto master server client

用变基解决变基

git pull --rebase

把现有仓库导出为裸仓库

git clone --bare [library-name] [newlibrary-name]

复制你的裸仓库来创建一个新仓库

scp -r my_project.git user@git.example.com:/opt/git

强制提交

git push [remote-name] [branch-name] --force

丢弃当前全部暂存

git checkout .

查看当前版本号

git rev-parse HEAD

相关文章

网友评论

    本文标题:git常用命令

    本文链接:https://www.haomeiwen.com/subject/qnmauxtx.html