Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR homework #114

Open
wants to merge 107 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
982af8c
Update the repo.
321Aurora Oct 21, 2024
fa815f2
This is a test.
HydrogenZp Oct 29, 2024
23e6ac9
Create 123test
HydrogenZp Oct 29, 2024
a86affb
Add files via upload
HydrogenZp Oct 29, 2024
c9ffcc2
Delete _2024-finalproject/README1.md
HydrogenZp Oct 29, 2024
6e391b6
Delete _2024-finalproject/HydrogenZp/123
HydrogenZp Oct 29, 2024
dc355d5
First commit.
Oct 29, 2024
e99b722
Update README1.md
HydrogenZp Nov 1, 2024
202feee
Create photos
HydrogenZp Nov 1, 2024
e490aec
Delete _2024-finalproject/HydrogenZp/photos
HydrogenZp Nov 1, 2024
1f9d2aa
Create 1
HydrogenZp Nov 1, 2024
1c5de9f
Add files via upload
HydrogenZp Nov 1, 2024
4779a73
PR
Lndra09 Nov 2, 2024
3f711c9
PRhomework
Lndra09 Nov 3, 2024
b7f24a9
Revert "PRhomework"
Lndra09 Nov 3, 2024
a5f288e
PRhm
Lndra09 Nov 3, 2024
2184b4e
QiuYDvv's first commit.
Nov 3, 2024
c39225b
Open PR.
WiseL00k Oct 30, 2024
b053ca7
Add myGitLearn Experience in WiseL00k/README.md.
WiseL00k Nov 2, 2024
d8418ee
Answered some git questions in GitUsage.md.
WiseL00k Nov 2, 2024
f86d936
It's my second commit.
Oct 29, 2024
791d129
Changed the previous commit message.
WiseL00k Nov 3, 2024
c997ced
This is my git-homework,which simply describe my study contents and s…
lovodllt Nov 4, 2024
3e40760
This is the revised PR homework.
Lndra09 Nov 5, 2024
694343d
This is my homework.
Richard-cc172 Nov 6, 2024
f00e541
This is my homework1.
Richard-cc172 Nov 6, 2024
f29af17
Added: ZZPeng-ROOT's README.md
ZZPeng-ROOT Nov 6, 2024
ba9d4b1
Added task1-1.png
ZZPeng-ROOT Nov 6, 2024
0940195
Added task1-1.png
ZZPeng-ROOT Nov 6, 2024
5661b5f
Added: task1-2.png
ZZPeng-ROOT Nov 6, 2024
1f99c0a
Merge branch 'ZZPeng-ROOT'
ZZPeng-ROOT Nov 6, 2024
64d26d2
ZZPeng-ROOT's PR Final Edition
ZZPeng-ROOT Nov 6, 2024
8fa7a4c
Git's homework
Whathelp233 Nov 6, 2024
d4c1e7e
Delete _2024-finalproject/HydrogenZp/photos directory.
HydrogenZp Nov 6, 2024
7ed40b6
Create tmp.txt.
HydrogenZp Nov 6, 2024
6832d0e
Upload photos that are used in my homework.
HydrogenZp Nov 6, 2024
d39b7cc
Delete _2024-finalproject/HydrogenZp/photos/tmp.txt.
HydrogenZp Nov 6, 2024
43c11ba
Upload my homework.
HydrogenZp Nov 6, 2024
a314bdc
Continue to complete Git issues.
WiseL00k Nov 6, 2024
de26567
Test question2 firstly.
WiseL00k Nov 6, 2024
760a570
Revert "Test question2 firstly."
WiseL00k Nov 6, 2024
14e8bb7
Test question2 secondly.
WiseL00k Nov 6, 2024
a1cefed
Complete Git Issue 1 and part of Issue 2.
WiseL00k Nov 6, 2024
1ce8f14
QiuYDvv' second commit add some photos.
Nov 7, 2024
0abb62f
Update README.md.
GL0752 Nov 7, 2024
03c50c8
add homeword:GIT application
Nov 7, 2024
ca6fdde
Update README.md.
GL0752 Nov 7, 2024
0041a92
Update all.
GL0752 Nov 7, 2024
134acfe
Update all.
GL0752 Nov 7, 2024
014ee50
Update all.
GL0752 Nov 7, 2024
898d48d
Finished all git issues.
WiseL00k Nov 7, 2024
efb551c
Supplement WiseL00k/README.md.
WiseL00k Nov 7, 2024
49117f7
Rename README1.md to README.md.
HydrogenZp Nov 7, 2024
b8257b4
Update git project.
321Aurora Nov 8, 2024
acd24e0
Resolve conflict.
Nov 8, 2024
3221f9e
Rename folder to 2024-finalproject.
HydrogenZp Nov 8, 2024
942463f
Merge branch '321Aurora:master' into master
ZiDXie Nov 8, 2024
d5498bc
Copy files.
Nov 8, 2024
f0438a9
Rename _2024-finalproject to 2024-finalproject.
WiseL00k Nov 8, 2024
fdf3a84
Add photos and sentences.
lain-2 Nov 8, 2024
858468e
Merge branch '321Aurora:master' into pull_request
muye665 Nov 8, 2024
cda291c
move _2024-/. file to 2024-/. , delete _2024-/.
Nov 8, 2024
7c4cb94
The second pr is here.
lovodllt Nov 8, 2024
c2740b6
Push the 2024-finalproject.
Richard-cc172 Nov 8, 2024
0c1e3d0
update
Whathelp233 Nov 9, 2024
3eb71dc
This is the second PR homework.
Lndra09 Nov 9, 2024
3ad191a
Change file's name.
Lndra09 Nov 9, 2024
5645b76
Delete old.
Nov 9, 2024
1a4bd1d
Merge pull request #49 from ZZPeng-ROOT/master
321Aurora Nov 10, 2024
373f2a0
Merge pull request #67 from lain-2/master
321Aurora Nov 10, 2024
29d305c
Merge pull request #64 from GL0752/GL0752
321Aurora Nov 10, 2024
31c69b8
Merge pull request #52 from Whathelp233/Whathelp233
321Aurora Nov 10, 2024
b6fb39b
Merge pull request #61 from muye665/pull_request
321Aurora Nov 10, 2024
ff12942
Update git repo.
321Aurora Nov 10, 2024
5107b97
Update my repo.
321Aurora Nov 10, 2024
c522bda
Slove the second conflict
Nov 10, 2024
bd5e5ae
Slove the second conflict again.
Nov 10, 2024
098f640
Slove the second conflict at the third time.
Nov 10, 2024
4c60b0f
Slove the second conflict at the forth time.
Nov 10, 2024
b78dfa9
Slove the second conflict at the fifith time.
Nov 10, 2024
b6c468b
Slove the second conflict at the sixth time.
Nov 10, 2024
3f413bf
Slove the second conflict at the seventh time.
Nov 10, 2024
003517b
Update README.md
QiuYDvv Nov 10, 2024
90c2f99
Merge branch 'master' into final-project-branch
Richard-cc172 Nov 10, 2024
ae681c1
Merge branch 'master' into master
Lndra09 Nov 10, 2024
3677321
Slove the second conflict at the eighth time.
Nov 10, 2024
2392f3d
Change file's name.
Lndra09 Nov 10, 2024
526af38
Slove the second conflict at many times.
Nov 10, 2024
165d525
Slove the second conflict at many times.
Nov 10, 2024
89fe7b8
Slove the second conflict at many times.
Nov 10, 2024
3edcb68
Update README.md
QiuYDvv Nov 10, 2024
6c83b08
Slove the second conflict at the forth time.
Nov 10, 2024
94689e0
Slove the second conflict at the forth time.
Nov 10, 2024
6780cf6
Add final project files for xyx-enwei
xyx-enwei Nov 10, 2024
8d9a97a
Merge branch 'master' into master
QiuYDvv Nov 10, 2024
e976b77
Merge branch 'master' of github.com:Lndra09/git_2024
Lndra09 Nov 10, 2024
134e021
Change file's name.
Lndra09 Nov 10, 2024
dd91b0f
Solve conflicts.
HydrogenZp Nov 10, 2024
8532019
Merge pull request #27 from ZiDXie/master
321Aurora Nov 10, 2024
974ab4d
Merge branch 'master' into master
WiseL00k Nov 10, 2024
9313881
Merge pull request #22 from HydrogenZp/master
321Aurora Nov 10, 2024
add37b7
Merge pull request #24 from QiuYDvv/master
321Aurora Nov 10, 2024
c0f648c
Merge pull request #70 from xyx-enwei/master
321Aurora Nov 10, 2024
b710dfc
Merge pull request #26 from WiseL00k/master
321Aurora Nov 10, 2024
34565c7
Merge pull request #38 from lovodllt/master
321Aurora Nov 10, 2024
a423401
Merge pull request #46 from Richard-cc172/final-project-branch
321Aurora Nov 10, 2024
8d78675
Change file's name.
Lndra09 Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added 2024-finalproject/.DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions 2024-finalproject/GL0752/Git_application.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ***Git应用***

**1.** 方式一:使用git reset --hard HEAD 把工作区和暂存区都恢复到最后一次提交的状态,所有未提交的修改都会被丢弃。由于--hard参数会强制覆盖工作区的修改,使用时需考虑考虑。

![图片1](./images/图1.png)

方式二:使用git checkout -- <文件名> 这将把指定文件恢复到最后一次提交的状态。

![图片2](./images/图2.png)

**2.** 不修改历史记录:git reset --soft <commit_hash> 将 HEAD 指针移动到指定的提交,但是不会更改工作目录和暂存区的内容。

![图片3](./images/图3.png)

修改历史记录:git reset --hard <commit_hash>:将 HEAD 指针移动到指定的提交,并重置工作目录和暂存区,使其与指定提交的状态完全一致。这会完全丢弃从指定提交之后的所有更改,并且无法恢复。

![图片4](./images/图4.png)

**3.** 方式一:使用rebase命令,将一系列提交从一个分支上“复制”并“粘贴”到另一个分支上。

git checkout feature-branch

git rebase master

git checkout master

git merge feature-branch

![图片5](./images/图5.png)

方式二:使用 cherry-pick`命令合并特定提交,将某个分支上的特定提交合并到其他分支。

git checkout master

git cherry-pick <commit-hash>

![图片6](./images/图6.png)
10 changes: 10 additions & 0 deletions 2024-finalproject/GL0752/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ***学习总结***

**1.** 这门课程开始,我们根据教程学会了双系统ubuntu的安装,并解决了在安装和配置系统时所遇到的各种问题;此外,ubuntu的使用与windows有很大的差别,需要去适应各种操作。

**2.** 课程介绍了Linux系统架构和命令行环境的强大功能,通过学习,我掌握了许多常用的命令并学会了数据整理的基本方法和技巧,了解了正则运算的基本使用。

**3.** 理解了CMake的基本概念和工作原理,掌握了CMake的基本命令,如cmake、make等,以及它们的基本用法。学会了如何编写基本CMakeLists.txt文件。 理解了Catkin工作空间的概念和结构,了解了Catkin构建系统的工作流程,即使用catkin_make或catkin build命令编译整个工作空间。

**4.** Git是一款分布式版本控制系统,在多人协作的项目开发中发挥着重要作用。在课程中学习了如何在一个新建的目录下创建Git仓库和克隆github仓库。掌握了git add命令,用于将修改的文件添加到暂存区;git commit命令将暂存区的文件提交到仓库,并附上提交说明;git log命令,用于查看提交历史记录。学习了如何创建分支以及如何合并分支到主分支的方法。并最终用git push的相关命令,用于将本地修改推送到远程仓库或从远程仓库拉取最新代码。

Binary file added 2024-finalproject/GL0752/images/图1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/GL0752/images/图2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/GL0752/images/图3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/GL0752/images/图4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/GL0752/images/图5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/GL0752/images/图6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
203 changes: 203 additions & 0 deletions 2024-finalproject/HydrogenZp/GitHomework.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Git Homework-By ZhongZhipeng

## Task 1:"若你已经修改了部分文件、并且将其中的一部分加入了暂存区,应该如何回退这些修改,恢复到修改前最后一次提交的状态?给出至少两种不同的方式"

### Solutions:

#### Solution 1

使用

```bash
$ git reset
```

<img src="./photos/t1p1.png" style="zoom: 50%;" />

#### Solution 2

使用

```bash
$ git rm --cached <file>
```

<img src="./photos/t1p2.png" style="zoom: 50%;" />

## Task 2:"若你已经提交了一个新版本,需要回退该版本,应该如何操作?分别给出不修改历史或修改历史的至少两种不同的方式"

### Solutions

#### Solution 1.1(修改历史):

使用如下命令进行回退

```bash
$ git reset --hard <commit_hash>^
```



先在`~/githw`中创建一个`reademe.txt`文件,插入文本如图所示,作为第一个版本

<img src="./photos/t2p1.png" style="zoom: 50%;" />

将其`commit`后修改,在文本末添加语句如图

<img src="./photos/t2p2.png" style="zoom:50%;" />

同样地,将其作为修改后的版本2并`commit`,此时log如图

![](./photos/t2p3.png)

这时,使用

```bash
$ git reset --hard HEAD^
```

一个幂指符号^表示上一版本,两个则表示上两个版本

此时可以看到版本已切回Version 1,打印readme.txt的内容,显示为第上版本的

![](./photos/t2p4.png)

查看此时的log

![](./photos/t2p5.png)

说明该方法为修改历史的一种方式



#### Solution 1.2(修改历史):

使用如下命令

```bash
$ git rebase -i <commit_hash>^
```

同Solution1.1编辑并修改reademe.txt

<img src="./photos/t2p10.png" style="zoom: 50%;" />

<img src="./photos/t2p11.png" style="zoom:50%;" />

对修改后的文件commit

![](./photos/t2p12.png)

执行命令

```bash
$ git rebase -i HEAD^
```

并修改弹出的文件(将pick改为drop)

![](./photos/t2p13.png)

![](./photos/t2p14.png)

保存并退出

![](./photos/t2p15.png)

显示版本已回退

![](./photos/t2p16.png)

#### Solution 2.1(不修改历史):

使用如下命令

```bash
$ git reset --soft HEAD
```

修改Solution 1中的readme.txt文件并commit

<img src="./photos/t2p6.png" style="zoom:50%;" />

![](./photos/t2p7.png)

此时使用

```bash
$ git reset --soft HEAD
```

可以发现commit已被回退至暂存区

![](./photos/t2p8.png)

查看文件内容

![](./photos/t2p9.png)

文件内容并未改变



#### Solution 2.2

使用

```bash
$ git revert HEAD
```

撤销提交

对readme.txt的操作同以上三种方法,在此省略展示

执行该命令

![](./photos/t2p17.png)

撤回了上一个版本的提交

![](./photos/t2p18.png)



## Task 3 :"我们已经知道了合并分支可以使用 merge,但这不是唯一的方法,给出至少两种不同的合并分支的方式"

### Solutions

#### Solution 1

使用

```bash
$ git rebase
```



如图,我将一个内容为空的readme.txt文件commit到了master分支,随后切换到feature分支并往readme.txt添加字符(对文件进行修改),随后commit

然后切换到master分支并使用上述命令

![](./photos/t3p1.png)

打开文件,文件内容证实已进行分支合并

<img src="./photos/t3p2.png" style="zoom: 33%;" />

#### Solution 2

```bash
$ git cherry-pick <commit_hash>
```

同Solution 1操作,陈述在此省略

执行上述操作,结果如图

<img src="./photos/t3p3.png" style="zoom: 50%;" />

打开文件,结果如图,说明分支成功合并

<img src="./photos/t3p2.png" style="zoom: 33%;" />
18 changes: 18 additions & 0 deletions 2024-finalproject/HydrogenZp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Git学习笔记

## 1. Git的工作流程

![](photos/git-process.png)

## 2. Git的工作区与版本库及其常见命令

![](photos/wks.jpg)

工作区的文件`add`到index(暂存区)后需要`commit`到master分支



当对工作区修改(或新增)的文件执行`git add`命令时,暂存区的目录树被更新,同时工作区修改(或新增)的文件内容被写入到对象库中的一个新的对象中,而该对象的ID被记录在暂存区的文件索引中。(用`git add filename`对指定文件提交到暂存区,用`git add .`对当前目录下所有文件提交到暂存区)

当对暂存区执行`commit`命令后,暂存区的所有文件将会被提交到当前的分支(图中为master)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t1p1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t1p2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024-finalproject/HydrogenZp/photos/t2p8.png
Binary file added 2024-finalproject/HydrogenZp/photos/t2p9.png
Binary file added 2024-finalproject/HydrogenZp/photos/t3p1.png
Binary file added 2024-finalproject/HydrogenZp/photos/t3p2.png
Binary file added 2024-finalproject/HydrogenZp/photos/t3p3.png
Binary file added 2024-finalproject/HydrogenZp/photos/wks.jpg
106 changes: 106 additions & 0 deletions 2024-finalproject/QiuYDvv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# 在本门课程中我学习了git版本控制系统的基本用法,学习如何使用个git来管理工作空间代码
# git简介
- Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
- Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。
- Git 与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持
# 在ubuntu系统中安装git的命令
```shell
apt-get install git
```
# git配置
```shell
git config --global user.name "runoob"
#初始化用户名
git config --global user.email [email protected]
#初始化邮箱
#--global对所有仓库有效
```
# git的工作区、暂存区、版本库
1. 工作区是repo里除了.git文件之外的位置,是平时修改代码的位置
2. 暂存区是工作区和版本库之间的过渡阶段
3. 版本库是git存放版本信息的位置,提交到版本库的代码才真正被git管理
# 如何创建一个仓库
## git init
本地初始化仓库
```shell
mkdir my-project
cd my-project
git init
```
## git clone
远程克隆仓库到指定目录
```shell
git clone <repo> <directory>
```
# 文件的状态
- 未跟踪(Untracked): 新创建的文件最初是未跟踪的。它们存在于工作目录中,但没有被 Git 跟踪
- 已跟踪(Tracked): 通过 git add 命令将未跟踪的文件添加到暂存区后,文件变为已跟踪状态。
- 已修改(Modified): 对已跟踪的文件进行更改后,这些更改会显示为已修改状态,但这些更改还未添加到暂存区。
- 已暂存(Staged): 使用 git add 命令将修改过的文件添加到暂存区后,文件进入已暂存状态,等待提交。
- 已提交(Committed): 使用 git commit 命令将暂存区的更改提交到本地仓库后,这些更改被记录下来,文件状态返回为已跟踪状态。

# git 的常用命令
```shell
git add filename # 将单个文件添加到暂存区
git add . # 将工作区中的所有修改添加到暂存区
git status # 查看哪些文件在暂存区中
git commit -m "Commit message" # 将暂存区的更改提交到本地版本库
git log # 查看提交历史
git diff # 查看工作区和暂存区之间的差异
git diff --cached # 查看暂存区和最后一次提交之间的差异
git pull origin branch-name #使用 git pull命令从远程仓库获取更新。
git push origin branch-name #使用 git push 命令将本地版本库的提交推送到远程仓库。
```
# git的基本操作
## 创建仓库命令
```shell
git init #初始化仓库
git clone #拷贝一份远程仓库,也就是下载一个项目。
```
## 提交与修改
```shell
git add #添加文件到暂存区
git status #查看仓库当前的状态,显示有变更的文件。
git diff #比较文件的不同,即暂存区和工作区的差异。
git difftool #使用外部差异工具查看和比较文件的更改。
git range-diff #比较两个提交范围之间的差异。
git commit #提交暂存区到本地仓库。
git reset #回退版本。
git rm #将文件从暂存区和工作区中删除。
git mv #移动或重命名工作区文件。
git notes #添加注释。
git checkout #分支切换。
git switch #(Git 2.23 版本引入) 更清晰地切换分支。
git restore #(Git 2.23 版本引入) 恢复或撤销文件的更改。
git show #显示 Git 对象的详细信息。
```
## 提交日志
```shell
git log #查看历史提交记录
git blame <file> #以列表形式查看指定文件的历史修改记录
git shortlog #生成简洁的提交日志摘要
git describe #生成一个可读的字符串,该字符串基于 Git 的标签系统来描述当前的提交
```
## 远程操作
```shell
git remote #远程仓库操作
git fetch #从远程获取代码库
git pull #下载远程代码并合并
git push #上传远程代码并合并
git submodule #管理包含其他 Git 仓库的项目
```
# 分支管理
```shell
git checkout -b <branchname> #创建新分支并切换到该分支
git checkout (branchname) #切换分支命令
git branch #查看所有分支
git branch -r #查看远程分支
git branch -a #查看所有本地和远程分支
git merge <branchname> #将其他分支合并到当前分支
git add <conflict-file> #标记冲突文件解决
git commit #提交冲突文件
git branch -d <branchname> #删除本地分支
git branch -D <branchname> #强制删除未合并分支
git push origin --delete <branchname> #删除远程分支
```

Loading