Skip to content

Commit

Permalink
Add git
Browse files Browse the repository at this point in the history
  • Loading branch information
me2seeks committed Apr 7, 2024
1 parent f5258fa commit 03ea6f9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
2 changes: 2 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
- [Other categories](other_categories/README.md)
- [archlinux](other_categories/linux/archlinux.md)
- [git](other_categories/git.md)
- [netcat](other_categories/netcat.md)
- [mkcert](other_categories/mkcert.md)
- [Issues and Solutions](issues_and_solutions/README.md)

94 changes: 47 additions & 47 deletions src/other_categories/git.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# git
# [git](git-scm.com)

## 强制 Git 在任何地方都使用固定的行结束符

Expand Down Expand Up @@ -32,63 +32,63 @@ git reset --hard

**1.初始化本地仓库**

```
```bash
git init <directory>
```

`<directory>` 是可选的,如果不指定,将使用当前目录。

**2.克隆一个远程仓库**

```
```bash
git clone <url>
```

**3.添加文件到暂存区**

```
```bash
git add <file>
```

要添加当前目录中的所有文件,请使用 . 代替 `<file>`,代码如下:

```
```bash
git add .
```

**4. 提交更改**

```
```bash
git commit -m "<message>"
```

如果要添加对跟踪文件所做的所有更改并提交。

```
```bash
git commit -a -m "<message>"
```

**5.从暂存区删除一个文件**

```
```bash
git reset <file>
```

**6.移动或重命名文件**

```
```bash
git mv <current path> <new path>
```

**7. 从存储库中删除文件**

```
```bash
git rm <file>
```

您也可以仅使用 `--cached` 标志将其从暂存区中删除

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

Expand All @@ -106,7 +106,7 @@ git rm --cached <file>

**13. 显示分支**

```
```bash
git branch
```

Expand All @@ -120,37 +120,37 @@ git branch

**14.创建一个分支**

```
```bash
git branch <branch>
```

你可以创建一个分支并使用 `checkout` 命令切换到它。

```
```bash
git checkout -b <branch>
```

**15.切换到一个分支**

```
```bash
git checkout <branch>
```

**16.删除一个分支**

```
```bash
git branch -d <branch>
```

您还可以使用 `-D` 标志强制删除分支。

```
```bash
git branch -D <branch>
```

**17.合并分支**

```
```bash
git merge <branch to merge into HEAD>
```

Expand All @@ -166,180 +166,180 @@ git merge <branch to merge into HEAD>

变基是将一系列提交移动或组合到新的基本提交的过程。

```
```bash
git rebase <branch to rebase from>
```

**19. 查看之前的提交**

```
```bash
git checkout <commit id>
```

**20. 恢复提交**

```
```bash
git revert <commit id>
```

**21. 重置提交**

```
```bash
git reset <commit id>
```

您还可以添加 `--hard` 标志来删除所有更改,但请谨慎使用。

```
```bash
git reset --hard <commit id>
```

**22.查看存储库的状态**

```
```bash
git status
```

**23.显示提交历史**

```
```bash
git log
```

**24.显示对未暂存文件的更改**

```
```bash
git diff
```

您还可以使用 `--staged` 标志来显示对暂存文件的更改。

```
```bash
git diff --staged
```

**25.显示两次提交之间的变化**

```
```bash
git diff <commit id 01> <commit id 02>
```

**26. 存储更改**

`stash` 允许您在不提交更改的情况下临时存储更改。

```
```bash
git stash
```

您还可以将消息添加到存储中。

```
```bash
git stash save "<message>"
```

**27. 列出存储**

```
```bash
git stash list
```

**28.申请一个藏匿处**

应用存储不会将其从存储列表中删除。

```
```bash
git stash apply <stash id>
```

如果不指定 `<stash id>`,将应用最新的 `stash`(适用于所有类似的 `stash` 命令)

您还可以使用格式 `stash@{<index>}` 应用存储(适用于所有类似的存储命令)

```
```bash
git stash apply stash@{0}
```

**29.删除一个藏匿处**

```
```bash
git stash drop <stash id>
```

**30.删除所有藏匿处**

```
```bash
git stash clear
```

**31. 应用和删除存储**

```
```bash
git stash pop <stash id>
```

**32.显示存储中的更改**

```
```bash
git stash show <stash id>
```

**33.添加远程仓库**

```
```bash
git remote add <remote name> <url>
```

**34. 显示远程仓库**

```
```bash
git remote
```

添加 `-v` 标志以显示远程存储库的 URL。

```
```bash
git remote -v
```

**35.删除远程仓库**

```
```bash
git remote remove <remote name>
```

**36.重命名远程存储库**

```
```bash
git remote rename <old name> <new name>
```

**37. 从远程存储库中获取更改**

```
```bash
git fetch <remote name>
```

**38. 从特定分支获取更改**

```
```bash
git fetch <remote name> <branch>
```

**39. 从远程存储库中拉取更改**

```
```bash
git pull <remote name> <branch>
```

**40.将更改推送到远程存储库**

```
```bash
git push <remote name>
```

**41.将更改推送到特定分支**

```
```bash
git push <remote name> <branch>
```

0 comments on commit 03ea6f9

Please sign in to comment.