Git

115 阅读4分钟

一. Git总结

1. 工作流程

一般工作流程如下:

  • 克隆 Git 资源作为工作目录。
  • 在克隆的资源上添加或修改文件。
  • 如果其他人修改了,你可以更新资源。
  • 在提交前查看修改。
  • 提交修改。
  • 在修改完成后,如果发现错误,可以撤回提交并再次修改并提交。

2. 基本操作

命令说明示例
git init自己创一个Git版本库,初始化,生成.git文件在适合的文件夹下:git init
git clonegitlab服务器拉取仓库代码到指定文件夹(提前cd进入)git clone http://119.3.199.81:8888/neuq202208/team04.git
git config配置开发者用户名和邮箱①安装后-指定名称和邮箱: git config --global user.name "Your Name" git config --global user.email "email@example.com" ②查看所有配置信息: git config -l ③查看邮箱: git config user.email
git branch操作分支创建分支:git branch feature/team04-bak
删除分支:git branch -d feature/team04-bak
查看分支:git branch
git checkout切换分支创建并切换到分支:git checkout -b feature/team04
切换分支:git checkout feature/team04
git status查看文件变动状态以下四种常见状态
① Untracked files → ⽂件未被跟踪;(根据提示进一步操作)
② Changes not staged for commit → 文件还没有add入缓存区
③ Changes to be committed → ⽂件已暂存,这是下次commit的内容;
④ Changes but not updated → ⽂件被修改,但并没有添加到暂存区。如果 commit 时没有带 -a 选项,这 个状态下的⽂件不会被提交。
git add添加文件变动到暂存区添加所有文件: git add .
添加指定文件: git add demo.md
git commit提交文件变动到版本库(Repository)初始第一次添加后的提交
git commit -m "add test1.txt"
后续修改或删除后的提交(非首次添加),不用add,一步到位:
git commit -am "edit/delete test2.txt"
git push将本地的代码改动推送到服务器初始化连接:
git push --set-upstream origin feature/team04-bak
or git push -u origin feature/team04-bak
git pull将服务器上的最新代码拉取到本地
(远程分支有新的 commit 未同步到本地)
拉取默认当前分支:
git pull
拉取选定远程分支:
git pull origin team04
--rebase拉取,使log日志变得干净:
git pull --rebase origin master
git fetch用于从远程获取代码库,提取更新的数据(有提示,代表已更新)git fetch origin
git merge在执行 git fetch 之后紧接着执行git merge远程分支到现在所在的任意分支git merge origin/feature/team04

3. 细节命令

文件控制说明
mkdir创建文件夹
cdgit bash中文件夹间跳转——退回上一级cd..——cd e:——cd train
注:cmd主盘之间直接e:,不用cd
pwd查看当前目录
touch创建文件
cat查看文件内容
vim创建并编辑文件

二. Markdown总结

1.基本语法

这些是 John Gruber 的原始设计文档中列出的元素。所有 Markdown 应用程序都支持这些元素。

元素Markdown 语法
标题(Heading)# H1## H2### H3
粗体(Bold)**bold text**
斜体(Italic)*italicized text*
引用块(Blockquote)> blockquote
有序列表(Ordered List)1. First item
2. Second item
3. Third item
无序列表(Unordered List)- First item
- Second item
- Third item
代码(Code)`code`
分隔线(Horizontal Rule)---
链接(Link)[title](https://www.example.com)
图片(Image)![alt text](image.jpg)

2.扩展语法

这些元素通过添加额外的功能扩展了基本语法。但是,并非所有 Markdown 应用程序都支持这些元素。

元素Markdown 语法
表格(Table)`SyntaxDescription<br>----------------------<br>HeaderTitle<br>ParagraphText`
代码块(Fenced Code Block){ "firstName": "John", "lastName": "Smith", "age": 25}
脚注(Footnote)Here's a sentence with a footnote. [^1] [^1]: This is the footnote.
标题编号(Heading ID)### My Great Heading {#custom-id}
定义列表(Definition List)term: definition
删除线(Strikethrough)~~The world is flat.~~
任务列表(Task List)- [x] Write the press release
- [ ] Update the website
- [ ] Contact the media

问题总结

1. git add 文件到暂存区时,出现:LF will be replaced by CRLF

  • 错误日志
    • 执行命令:git add test.md
    • 报如下错误:
warning: LF will be replaced by CRLF in test.md.
The file will have its original line endings in your working directory.
  • 解决方案

    警告:LF将被test.md中的CRLF替换。

    该文件将在工作目录中以其原始行结尾。

    出现此问题是因为不同操作系统的使用的换行符不同:

    Linux / Unix 采用换行符LF表示下一行

    Windows 采用回车+换行 CRLF表示下一行

    • 可以通过设置 core.autocrlf 的值解决

    • $ git config --global core.autocrlf false 关闭自动转换

  • 参考资料

    blog.csdn.net/shaomjc/art…

2. git push时出现 fatal: unable to access ‘xxx‘: OpenSSL SSL_read: Connection was reset, errno 10054

感悟

  • 官网是最权威优质的学习资源
  • 多和组员沟通交流,有很多意想不到的收获
  • 出现技术问题及时记录总结