zoukankan      html  css  js  c++  java
  • =git========》命令大全

    代码恢复修改(并且sync):
    例drv目录:

    cd drv/

    git status

    git clean

    git clean -dxf

    git status

    git checkout --.

    git status

    上库操作命令:

    git add file

    git status .

    git commit .

    repo upload .

    修改之后的提交操作命令:

    git status .

    git add file

    git commit --amend

    repo upload .

    合并多个commit:

    git rebase - i commit_id

    id为要合并的commit之前的id

    重置到某一次的提交:

    git reset --hard commit_id


    名词

    master:默认开发分支

    origin:默认远程版本库

    Index/stage:暂缓区

    Workspace:工作区

    Repository:仓库区(本地仓库)

    Remote:远程仓库

    一. 新建代码库

    1. # 在当前目录新建一个代码仓库

    2. git init

    3. # 新建一个目录,将其初始化为Git仓库

    4. git init [project-name]

    5. # 下载一个项目和它的整个代码历史

    6. git clone[url]

    二.配置

    git的设置文件为.gitconfig,它可以在用户主目录下(全局配置)

    1. # 显示当前的Git配置

    2. git config --list

    3. # 编辑Git配置文件

    4. git config -e [--global]

    5. # 设置提交代码时的用户信息

    6. git config [--global]

    7. # 设置提交代码时的用户信息

    8. git config [--global] user.name "[name]"

    9. git config [--global] user.email "email address"

    三.增加/删除/修改文件

    1. # 查看状态

    2. git status

    3. # 查看变更内容

    4. git diff

    5. # 添加指定文件到暂存区

    6. git add [file1] [file2]

    7. # 添加指定目录到暂缓区,包括子目录

    8. git add .

    9. # 添加每个变化前,都会要求确认

    10. #对于同一个文件的多处变化,可以实现分次提交

    11. git add -p

    12. # 删除工作区文件,并且将这次删除放入=暂缓区

    13. git rm[file1] [file2]...

    14. # 停止追踪指定文件,但该文件会保留在工作区

    15. git rm --cached [file]

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

    17. git mv [file-oigin] [file-renamed]

    代码提交

    1. # 提交暂缓区至仓库区

    2. git commit -m [message]

    3. # 提交暂缓区的指定文件到仓库区

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

    5. # 提交工作区自上次commit之后的变化,直接到仓库区

    6. git commit -a

    7. # 使用一次新的commit,替代上一次提交

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

    9. git commit --amend -m [message]

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

    11. git commit --amend [file1] [file2]...

    五.分支

    1. # 显示所有的本地分支

    2. git branch

    3. # 列出所有的远程分支

    4. git branch -r

    5. # 列出所有的本地分支和远程分支

    6. git branch -a

    7. # 新建一个分支,但是依然停留在当前分支

    8. git branch [branch-name]

    9. # 新建一个分支,并与指定的远程分支建立追踪关系

    10. git branch --track [branck] [remote-name]

    11. # 删除远程分支

    12. git push origin --delete [branch-name]

    13. git branch -dr [remote/branch]

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

    15. git checkout -b [branch]

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

    17. git checkout [branch-name]

    18. # 切换到上一个分支

    19. git checkout -

    20. # 建立追踪关系,在现有分支与指定的远程分支之间

    21. git branch --set-upstream [branch] [remote-branch]

    22. # 合并指定分支到当前分支

    23. git merge [branch]

    24. # 衍合指定分支到当前分支

    25. git rebase <branch>

    26. # 选择一个commit,合并到当前分支

    27. git cherry-pick [commit]

    六. 标签

    1. # 列出所有本地标签

    2. git tag

    3. # 基于最新提交创建的标签

    4. git tag <tagname>

    5. # 删除标签

    6. git tag -d <tagname>

    7. # 删除远程tag

    8. git push origin refs/tages/[tagename]

    9. # 查看tag信息

    10. git show [tag]

    11. # 提交指定tag

    12. git push [remote] [tag]

    13. # 提交所有tag

    14. git push [remote] --[tag]

    15. # 新建一个分支,指向某个tag

    16. git checkout -b [branch] [tag]

    七.查看信息

    1. # 显示有变更的文件

    2. git status

    3. # 显示当前分支的版本历史

    4. git log

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

    6. git log --stat

    7. # 搜索提交历史,根据关键词

    8. git log -s [keyword]

    9. # 显示某个commit之后的所有变动,每个commit占据一行

    10. git log [tag] HEAD --pretty=format:%s

    11. # 显示某个commit之后的所有变动,其“提交说明”必须符合搜索条件

    12. git log [tag] HEAD --grep feature

    13. # 显示某个文件的版本历史,包括文件改名

    14. git log --follow [file]

    15. git whatchanged [file]

    16. # 显示指定文件相关的每一次diff

    17. git log -p [file]

    18. # 显示过去的5次提交

    19. git log -5 --pretty --oneline

    20. # 显示所有提交过的用户,按提交次数排序

    21. git shortlog -sn

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

    23. git blame [file]

    24. # 显示暂缓区和工作区的差异

    25. git diff

    26. # 显示暂缓区和上一个commit的差异

    27. git diff HEAD

    28. # 显示两次提交之间的差异

    29. git diff [first-branch]...[second-branch]

    30. # 显示某次提交发生变化的文件

    31. git show --name-only [commit]

    32. 当前版本的commitid

    33. git rev-parse HEAD

    远程操作

    1. # 下载远程仓库的所有变动

    2. git fetch [remote]

    3. # 取回远程仓库的变化,并与本地分支合并

    4. git pull [remote] [branch]

    5. # 显示所有的远程仓库

    6. git remote -v

    7. # 显示某个远程仓库的信息

    8. git remote show [remote]

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

    10. git remote add [shortname] [url]

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

    12. git push [remote] [branch]

    13. # 强行推送当前分支到远程仓库,即使有冲突

    14. git push [remote] --force

    15. # 推送所有的分支到远程仓库

    16. git push [remote] --all

    九.撤销

    1. # 撤销工作目录中所有未提交文件的修改内容

    2. git reset --hard HEAD

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

    4. git checkout HEAD [file]

    5. # 撤销指定的未提交文件的修改内容到最近的一次提交
    6.  git checkout --[file]

    7. # 撤销指定的提交

    8. git revert <commit>

    >
    作者:豌豆果果
    出处:https://www.cnblogs.com/hylogs/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    觉得有所帮助,可以请果果喝咖啡哟^_^!

  • 相关阅读:
    全面解析Vue.nextTick实现原理
    js 宏任务和微任务
    模拟实现ES6的set类
    git客户端出现libpng warning: iCCP: known incorrect sRGB profile
    js封装、继承
    js单例模式
    并行运行多个python虚拟机
    关于场景服务的一些想法
    关于不能对闭包函数进行热更新的问题
    Python string interning原理
  • 原文地址:https://www.cnblogs.com/hylogs/p/13374671.html
Copyright © 2011-2022 走看看