• Git操作


    1.版本控制 

     

     

    Git与SVN最主要区别

    2.下载、配置

    2.1 镜像下载地址

    CNPM Binaries Mirror (npmmirror.com)https://registry.npmmirror.com/binary.html?path=git-for-windows/

    2.2 基本linux命令

    2.3 基本配置

    2.3 常用指令配置别名

    #用于输出git提交日志
    alias git-log='git log --all --pretty=oneline --graph --abbrev-commit'
    #用于输出当前目录所有文件及基本信息
    alias ll='ls -a1'

    3.Git基本理论(核心)

    3.1 工作区域 

     

     

    3.2 工作流程 

    4.分支

    4.1分支的操作

      

     4.2分支使用流程

    5. 本地仓库的操作

     

     

    1. 1. 新建一个text.txt
    2. ----------------------------------------------------------
    3. $ touch text.txt
    4. 2. 往text.txt中写入字符串并查看
    5. ----------------------------------------------------------
    6. $ vim text.txt
    7. $ cat text.txt
    8. hello git
    9. 3. add操作
    10. ----------------------------------------------------------
    11. $ git add .
    12. warning: LF will be replaced by CRLF in text.txt.
    13. The file will have its original line endings in your working directory
    14. 4. 查看文件状态
    15. ----------------------------------------------------------
    16. $ git status
    17. On branch master
    18. No commits yet
    19. Changes to be committed:
    20. (use "git rm --cached ..." to unstage)
    21. new file: text.txt
    22. 5. commit操作
    23. ----------------------------------------------------------
    24. $ git commit -m "第一次提交"
    25. [master (root-commit) 2f93118] 第一次提交
    26. 1 file changed, 1 insertion(+)
    27. create mode 100644 text.txt
    28. 6. 查看日志
    29. ----------------------------------------------------------
    30. $ git log
    31. commit 2f9311838ec6a0891840f602f780186bc31f7baa (HEAD -> master)
    32. Author: “gyx” <729389749@163.com>
    33. Date: Tue Jun 14 12:18:41 2022 +0800
    34. 第一次提交
    35. 7. 修改文件内容
    36. ----------------------------------------------------------
    37. $ vim text.txt
    38. 8. 再次add操作
    39. ----------------------------------------------------------
    40. $ git add .
    41. warning: LF will be replaced by CRLF in text.txt.
    42. The file will have its original line endings in your working directory
    43. 9. 再次commit操作
    44. ----------------------------------------------------------
    45. $ git commit -m "第二次提交"
    46. [master 3430517] 第二次提交
    47. 1 file changed, 1 insertion(+)
    48. 10. 再次查看文件状态
    49. ----------------------------------------------------------
    50. $ git status
    51. On branch master
    52. nothing to commit, working tree clean
    53. 11. 再次查看日志
    54. ----------------------------------------------------------
    55. $ git log
    56. commit 3430517a8325b59f6d5377d5c8aca6dd124e46c7 (HEAD -> master)
    57. Author: “gyx” <729389749@163.com>
    58. Date: Tue Jun 14 12:23:25 2022 +0800
    59. 第二次提交
    60. commit 2f9311838ec6a0891840f602f780186bc31f7baa
    61. Author: “gyx” <729389749@163.com>
    62. Date: Tue Jun 14 12:18:41 2022 +0800
    63. 第一次提交
    64. 12. 版本回退
    65. ----------------------------------------------------------
    66. $ git reset --hard 2f9311838ec6a0891840f602f780186bc31f7baa
    67. HEAD is now at 2f93118 第一次提交
    68. 13. 查看版本
    69. ----------------------------------------------------------
    70. $ cat text.txt
    71. hello git
    72. 14. 版本回退
    73. ----------------------------------------------------------
    74. $ git reset --hard 3430517a8325b59f6d5377d5c8aca6dd124e46c7
    75. HEAD is now at 3430517 第二次提交
    76. 15. 查看版本
    77. ----------------------------------------------------------
    78. $ cat text.txt
    79. hello git
    80. hello git2
    81. 16. 清屏
    82. ----------------------------------------------------------
    83. $ clear
    84. 17. 清除后查看版本
    85. ----------------------------------------------------------
    86. $ git reflog
    87. 3430517 (HEAD -> master) HEAD@{0}: reset: moving to 3430517a8325b59f6d5377d5c8aca6dd124e46c7
    88. 2f93118 HEAD@{1}: reset: moving to 2f9311838ec6a0891840f602f780186bc31f7baa
    89. 3430517 (HEAD -> master) HEAD@{2}: commit: 第二次提交
    90. 2f93118 HEAD@{3}: commit (initial): 第一次提交
    91. 18. 版本回退
    92. ----------------------------------------------------------
    93. $ git reset --hard 3430517
    94. HEAD is now at 3430517 第二次提交
    95. 19. 查看版本
    96. ----------------------------------------------------------
    97. $ cat text.txt
    98. hello git
    99. hello git2

    6.远程仓库

    6.1使用码云

     生成公钥要连续三个回车才有!!!

     

    6.2 本地仓库推到码云

    1. 1. 初始化一个本地仓库
    2. ----------------------------------------------------------
    3. $ git init
    4. Initialized empty Git repository in E:/java/01_WorkSpace/git/git-demo/.git/
    5. 2. 新增一个文件,写入字符串
    6. ----------------------------------------------------------
    7. $ touch text.txt
    8. $ vim text.txt
    9. $ cat text.txt
    10. hello
    11. java
    12. 3.新增远程仓库地址,并查看
    13. ----------------------------------------------------------
    14. $ git remote add origin git@gitee.com:YingXinChn/git-test.git
    15. $ git remote
    16. origin
    17. 4.添加
    18. ----------------------------------------------------------
    19. $ git add .
    20. warning: LF will be replaced by CRLF in text.txt.
    21. The file will have its original line endings in your working directory
    22. 5.commit
    23. ----------------------------------------------------------
    24. $ git commit -m "第一次提交"
    25. [master (root-commit) 1589a5a] 第一次提交
    26. 1 file changed, 2 insertions(+)
    27. create mode 100644 text.txt
    28. 6.push
    29. ----------------------------------------------------------
    30. $ git push origin master
    31. The authenticity of host 'gitee.com (212.64.63.215)' can't be established.
    32. ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
    33. This key is not known by any other names
    34. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    35. Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
    36. Enumerating objects: 3, done.
    37. Counting objects: 100% (3/3), done.
    38. Writing objects: 100% (3/3), 237 bytes | 118.00 KiB/s, done.
    39. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    40. remote: Powered by GITEE.COM [GNK-6.3]
    41. To gitee.com:YingXinChn/git-test.git
    42. * [new branch] master -> master

    6.3 克隆

     

    6.4 抓取和拉取 

     方法1:fetch+merge

    1. 1. 克隆到本地
    2. ----------------------------------------------------------
    3. $ git clone git@gitee.com:YingXinChn/git-test.git
    4. Cloning into 'git-test'...
    5. remote: Enumerating objects: 5, done.
    6. remote: Counting objects: 100% (5/5), done.
    7. remote: Compressing objects: 100% (3/3), done.
    8. remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
    9. Receiving objects: 100% (5/5), done.
    10. 2. 进入克隆的本地仓库
    11. ----------------------------------------------------------
    12. $ cd git-test
    13. 3. 查看日志
    14. ----------------------------------------------------------
    15. $ git-log
    16. * 8399698 (HEAD -> master, origin/master, origin/HEAD) add text02
    17. * 0e55e86 add text01
    18. 4. 抓取(不合并)
    19. ----------------------------------------------------------
    20. $ git fetch
    21. remote: Enumerating objects: 3, done.
    22. remote: Counting objects: 100% (3/3), done.
    23. remote: Compressing objects: 100% (2/2), done.
    24. remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
    25. Unpacking objects: 100% (2/2), 224 bytes | 2.00 KiB/s, done.
    26. From gitee.com:YingXinChn/git-test
    27. 8399698..38e4014 master -> origin/master
    28. 5. 查看日志(此时没有合并到本地master分支)
    29. ----------------------------------------------------------
    30. $ git-log
    31. * 38e4014 (origin/master, origin/HEAD) add text03
    32. * 8399698 (HEAD -> master) add text02
    33. * 0e55e86 add text01
    34. 6. 合并分支
    35. ----------------------------------------------------------
    36. $ git merge origin/master
    37. Updating 8399698..38e4014
    38. Fast-forward
    39. text03.txt | 0
    40. 1 file changed, 0 insertions(+), 0 deletions(-)
    41. create mode 100644 text03.txt
    42. 7. 再次查看日志,合并成功
    43. ----------------------------------------------------------
    44. $ git-log
    45. * 38e4014 (HEAD -> master, origin/master, origin/HEAD) add text03
    46. * 8399698 add text02
    47. * 0e55e86 add text01

    方法2:pull

  • 相关阅读:
    湖北移动中兴B860AV2.1_S905L_线刷固件包
    上周内容回顾
    广度优先搜索算法
    java-net-php-python-jsp网络考试系统计算机毕业设计程序
    电子科技大学 分布式系统 期末复习笔记
    元素可视区操作之client系列offset系列以及scroll系列
    系统开发视角下的诊断 ———— 车身控制(B)诊断故障
    工业设计能做出什么独特优势?
    ORACLE归档日志满,没法访问
    只因程序员写了一段爬虫,公司200人被端,是种什么体验?
  • 原文地址:https://blog.csdn.net/m0_63544124/article/details/125217932