image.png

    1. ##################### 仓库初始化 ####################
    2. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo
    3. $ git init
    4. Initialized empty Git repository in G:/git-repo/.git/
    5. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    6. $ ll
    7. total 12
    8. drwxr-xr-x 1 47345 197609 0 Jun 29 16:53 ./
    9. drwxr-xr-x 1 47345 197609 0 Jun 29 16:52 ../
    10. drwxr-xr-x 1 47345 197609 0 Jun 29 16:53 .git/
    11. ##################### 创建一个a.txt文件 ####################
    12. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    13. $ touch a.txt
    14. ##################### 查看文件修改的状态 ####################
    15. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    16. $ git status
    17. On branch master
    18. No commits yet
    19. Untracked files:
    20. (use "git add <file>..." to include in what will be committed)
    21. a.txt
    22. nothing added to commit but untracked files present (use "git add" to track)
    23. ##################### 将目录下所有文件加入暂存区 ####################
    24. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    25. $ git add .
    26. ##################### 再次查看文件修改的状态 ####################
    27. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    28. $ git status
    29. On branch master
    30. No commits yet
    31. Changes to be committed:
    32. (use "git rm --cached <file>..." to unstage)
    33. new file: a.txt
    34. ##################### 提交暂存区到本地仓库 ####################
    35. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    36. $ git commit -m 'adding a.txt to repo'
    37. [master (root-commit) 8b094a6] adding a.txt to repo
    38. 1 file changed, 0 insertions(+), 0 deletions(-)
    39. create mode 100644 a.txt
    40. ##################### 对a文件写入些内容 ####################
    41. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    42. $ vim a.txt
    43. ##################### 再次查看文件修改状态 ####################
    44. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    45. $ git status
    46. On branch master
    47. Changes not staged for commit:
    48. (use "git add <file>..." to update what will be committed)
    49. (use "git restore <file>..." to discard changes in working directory)
    50. modified: a.txt
    51. no changes added to commit (use "git add" and/or "git commit -a")
    52. ##################### 把修改后的文件添加到暂存区 ####################
    53. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    54. $ git add .
    55. warning: LF will be replaced by CRLF in a.txt.
    56. The file will have its original line endings in your working directory
    57. ##################### 再次查看状态 ####################
    58. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    59. $ git status
    60. On branch master
    61. Changes to be committed:
    62. (use "git restore --staged <file>..." to unstage)
    63. modified: a.txt
    64. ##################### 提交暂存区到本地仓库 ####################
    65. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    66. $ git commit -m 'update a.txt'
    67. [master 26efdc6] update a.txt
    68. 1 file changed, 1 insertion(+)
    69. ##################### 查看提交日志 ####################
    70. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    71. $ git log
    72. commit 26efdc650e02e9615660d1bbb2d130c4d5d90619 (HEAD -> master)
    73. Author: peng <“473459100@qq.com”>
    74. Date: Wed Jun 29 17:10:29 2022 +0800
    75. update a.txt
    76. commit 8b094a669ace594b10d9be8b965f161b02ba34ac
    77. Author: peng <“473459100@qq.com”>
    78. Date: Wed Jun 29 17:05:57 2022 +0800
    79. adding a.txt to repo
    80. ##################### 采用别名git-log查看提交日志 ####################
    81. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    82. $ git-log
    83. * 26efdc6 (HEAD -> master) update a.txt
    84. * 8b094a6 adding a.txt to repo
    85. ##################### 查看文件内容 ####################
    86. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    87. $ cat a.txt
    88. i am chinese!
    89. ##################### 版本回退 ####################
    90. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    91. $ git reset --hard 8b094a6
    92. HEAD is now at 8b094a6 adding a.txt to repo
    93. ##################### 再次查看提交日志 ####################
    94. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    95. $ git-log
    96. * 8b094a6 (HEAD -> master) adding a.txt to repo
    97. ##################### 目录下创建git忽略文件 ####################
    98. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    99. $ touch .gitignore
    100. ##################### 目录下创建一个b.a文件 ####################
    101. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    102. $ touch b.a
    103. ##################### 编辑git忽略文件,让git忽略.a文件 ####################
    104. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    105. $ vi .gitignore
    106. ##### 可以看到只有.gitignore文件没有加入到暂存区,a.b没报,被git忽略了 ########
    107. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    108. $ git status
    109. On branch master
    110. Untracked files:
    111. (use "git add <file>..." to include in what will be committed)
    112. .gitignore
    113. nothing added to commit but untracked files present (use "git add" to track)

    创建分支、切换分支、合并分支:

    1. ##################### master分支中切换到dev01分支 ####################
    2. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    3. $ git checkout dev01
    4. Switched to branch 'dev01'
    5. ##################### dev01分支中新建一个dev01.txt ####################
    6. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
    7. $ touch dev01.txt
    8. ##################### dev01.txt添加 ####################
    9. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
    10. $ git add .
    11. ##################### dev01.txt提交到仓库 ####################
    12. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
    13. $ git commit -m 'add dev01'
    14. [dev01 b3e84b5] add dev01
    15. 2 files changed, 0 insertions(+), 0 deletions(-)
    16. create mode 100644 b.a
    17. create mode 100644 dev01.txt
    18. ##################### 查看日志 ####################
    19. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
    20. $ git-log
    21. * b3e84b5 (HEAD -> dev01) add dev01
    22. | * d776e70 (master) add ignore file
    23. |/
    24. * 8b094a6 adding a.txt to repo
    25. ##################### 切换到master,观察两个分支的文件目录结构变化 ##############
    26. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
    27. $ git checkout master
    28. Switched to branch 'master'

    image.pngimage.png
    可以发现在dev01中创建的文件,在master中是没有的,可以通过合并两分支解决。

    1. ##################### 合并分支前要先切换到master ##############
    2. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
    3. $ git checkout master
    4. Switched to branch 'master'
    5. ##################### 将dev01分支合并到merge分支 ##############
    6. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    7. $ git merge dev01
    8. Merge made by the 'ort' strategy.
    9. b.a | 0
    10. dev01.txt | 0
    11. 2 files changed, 0 insertions(+), 0 deletions(-)
    12. create mode 100644 b.a
    13. create mode 100644 dev01.txt
    14. ##################### 查看修改日志 ##############
    15. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    16. $ git-log
    17. * 0fcb629 (HEAD -> master) Merge branch 'dev01'
    18. |\
    19. | * b3e84b5 (dev01) add dev01
    20. * | d776e70 add ignore file
    21. |/
    22. * 8b094a6 adding a.txt to repo

    Gitee码云配置:

    1. ##################### 生成SSH公钥 ##############
    2. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    3. $ ssh-keygen -t rsa
    4. Generating public/private rsa key pair.
    5. Enter file in which to save the key (/c/Users/47345/.ssh/id_rsa):
    6. /c/Users/47345/.ssh/id_rsa already exists.
    7. Overwrite (y/n)?
    8. ##################### 获取公钥,打开这个.pub文件即可 ##############
    9. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    10. $ cat ~/.ssh/id_rsa.pub
    11. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDm/UDDewd6/bbywFCZp9TIlmFSdaU6L3/sVTEJ/uWedv2SKpIoMJOUp3Iqnc9668+fQkB6zA7GdHVbCAHJ0st0OhCVvkKKKuB83CG8F7RmizVoDsduQTBRuXLLte4rUJOcd5tH9iOYqniERNYS/bsd47sh/WjlE/aL2ufdjOLZgpUWuG4MjgNFBqxKtkbFBubiAfcmM4svbjxqogriTxkMXMK8DylybikSsVM01nBTo+bsRRJMn1Pay3VfJ1fyMq7bbgRxuuW41VyXWPi/eCE/MkQnHK2iG5tRav4kJ9tevl6Rb+WntBHVeeqdKWU6h0jOhpEcZ5juOMfh3beI7Q+9ngZE2BbVdQA1HM8aa54cuuj/UxKNFUjz57rwrwmEtBZZgjOEc7Zv/zv2VMDF32FvZLdwB4tqWOTpfYw4WxBoaWmB9mu1cbHc8qPHEYIhNxEZKfc196jYnp+bjGnttfE446Vyq32EHzl0oV0RtDe7ovtrCvvdT7GEq6hGyd7JHDM= 47345@DESKTOP-O86FLIS
    12. ##################### 验证是否配置成功 ##############
    13. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    14. $ ssh -T git@gitee.com
    15. The authenticity of host 'gitee.com (212.64.63.190)' can't be established.
    16. ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
    17. This key is not known by any other names
    18. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    19. Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
    20. Hi 阿鹏! You've successfully authenticated, but GITEE.COM does not provide shell access.
    21. ##################### 添加远程仓库 ##############
    22. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    23. $ git remote add origin https://gitee.com/yudongshao/git_test.git
    24. ##################### 查看远程仓库 ##############
    25. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    26. $ git remote
    27. origin
    28. ##################### 推送到远程仓库 ##############
    29. 47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
    30. $ git push origin master:master
    31. Enumerating objects: 10, done.
    32. Counting objects: 100% (10/10), done.
    33. Delta compression using up to 4 threads
    34. Compressing objects: 100% (7/7), done.
    35. Writing objects: 100% (10/10), 805 bytes | 161.00 KiB/s, done.
    36. Total 10 (delta 3), reused 0 (delta 0), pack-reused 0
    37. remote: Powered by GITEE.COM [GNK-6.3]
    38. To https://gitee.com/yudongshao/git_test.git
    39. * [new branch] master -> master