美文网首页
Git常用命令速查表

Git常用命令速查表

作者: 周星星的学习笔记 | 来源:发表于2021-01-19 11:18 被阅读0次

    Git常用命令速查表小记

    Git常用命令速查表

    一、创建版本库

    1.克隆远程版本库

    git clone <url>
    

    2.初始化本地版本库

    git init
    

    二、修改和提交

    1.查看状态

    git status
    

    2.查看变更的内容

    git diff
    

    3.跟踪所有改动过的文件

    git add .
    

    4.跟踪指定的文件

    git add <file>
    

    5.文件改名

    git mv <old-file> <new-file>
    

    6.删除文件

    git rm <file>
    

    7.停止跟踪文件但不删除

    git rm --cached <file>
    

    8.提交所有更新过的文件

    git commit -m "commit message"
    

    9.修改最后一次提交

    git commit --amend
    

    三、暂存

    1.临时保存当前的修改

    git stash
    

    2.查看临时保存的记录列表

    git stash list
    

    3.恢复上一次临时保存的记录

    git stash pop
    

    4.清除所有临时保存的记录

    git stash clear
    

    四、查看提交历史

    1.查看提交历史

    git log
    

    2.查看指定文件的提交历史

    git log -p <file>
    

    3.以列表方式查看指定文件

    git blame <file>
    

    4.查看最新的提交历史记录的内容

    git show
    

    5.查看某条历史记录的内容

    git show <commit>
    

    五、撤销

    1.撤销工作目录中所有未提交

    git reset --hard HEAD
    

    2.撤销指定的未提交文件的修改内容

    git checkout HEAD <file>
    

    3.撤销指定的提交

    git revert <commit>
    

    六、分支与标签

    1.显示所有本地的分支

    git branch
    

    2.切换到指定分支或标签

    git checkout <branch/tag>
    

    3.创建新分支

    git branch <new-branch>
    

    4.删除本地分支

    git branch -d <branch>
    

    5.列出所有本地标签

    git tag
    

    6.基于最新提交创建标签

    git tag <tagname>
    

    7.删除标签

    git tag -d <tagname>
    

    七、合并和衍合

    1.合并指定分支到当前分支

    git merge <branch>
    

    2.衍合指定分支到当前分支

    git rebase <branch>
    

    八、远程操作

    1.查看远程版本库信息

    git remote -v
    

    2.查看指定远程版本库信息

    git remote show <remote>
    

    3.添加远程版本库

    git remote add <remote> <url>
    

    4.从远程库获取代码

    git fetch <remote>
    

    5.下载代码及快速合并

    git pull <remote> <branch>
    

    6.上传代码及快速合并

    git push <remote> <branch>
    

    7.删除远程分支或标签

    git push <remote>:<branch/tag-name>
    

    8.上传所有标签

    git push --tags
    

    相关文章

      网友评论

          本文标题:Git常用命令速查表

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