Git 帮忙

如果你遗记了命令或命令的选项,你能够应用 Git 帮忙。

在命令行中,有几种不同的应用帮忙命令的形式:

  • git command -help - 查看特定命令的所有可用选项
  • git help --all - 查看所有可能的命令

让咱们看看不同的命令。

Git -help 查看特定命令的选项

任何时候,如果你须要帮忙来记住特定命令的选项,你能够应用 git command -help

这将显示特定命令的所有可用选项:

usage: git commit [] [--] ...    -q, --quiet           suppress summary after successful commit    -v, --verbose         show diff in commit message templateCommit message options    -F, --file      read message from file    --author      override author for commit    --date          override date for commit    -m, --message                           commit message    -c, --reedit-message                           reuse and edit message from specified commit    -C, --reuse-message                           reuse message from specified commit    --fixup       use autosquash formatted message to fixup specified commit    --squash      use autosquash formatted message to squash specified commit    --reset-author        the commit is authored by me now (used with -C/-c/--amend)    -s, --signoff         add a Signed-off-by trailer    -t, --template                           use specified template file    -e, --edit            force edit of commit    --cleanup       how to strip spaces and #comments from message    --status              include status in commit message template    -S, --gpg-sign[=]                          GPG sign commitCommit contents options    -a, --all             commit all changed files    -i, --include         add specified files to index for commit    --interactive         interactively add files    -p, --patch           interactively add changes    -o, --only            commit only specified files    -n, --no-verify       bypass pre-commit and commit-msg hooks    --dry-run             show what would be committed    --short               show status concisely    --branch              show branch information    --ahead-behind        compute full ahead/behind values    --porcelain           machine-readable output    --long                show status in long format (default)    -z, --null            terminate entries with NUL    --amend               amend previous commit    --no-post-rewrite     bypass post-rewrite hook    -u, --untracked-files[=]                          show untracked files, optional modes: all, normal, no. (Default: all)    --pathspec-from-file                           read pathspec from file    --pathspec-file-nul   with --pathspec-from-file, pathspec elements are separated with NUL characterNote: You can also use --help instead of -help to open the relevant Git manual page

Git help --all 查看所有可能的命令

要列出所有可能的命令,能够应用 help --all 命令:

留神:这将显示一个十分长的命令列表

$ git help --all
````这将显示所有可能的命令列表。## 合并分支和解决抵触紧急修复曾经筹备好,当初让咱们合并 master 和 emergency-fix 分支。首先,咱们须要切换到 master 分支:`git checkout master`当初,咱们将以后分支(master)与 emergency-fix 合并:

git merge emergency-fix

更新 09f4acd..dfa79db
快进
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

因为 emergency-fix 分支间接来自于 master,并且在咱们工作时没有对 master 进行其余更改,Git 将其视为 master 的连续。因而,能够“快进”,将 master 和 emergency-fix 指向雷同的提交。因为 master 和 emergency-fix 当初实质上雷同,咱们能够删除 emergency-fix,因为它不再须要:

git branch -d emergency-fix

已删除分支 emergency-fix(是 dfa79db)。

### 合并抵触当初咱们能够切换到 hello-world-images 并持续工作。增加另一个图像文件(img\_hello\_git.jpg)并更改 index.html,以便显示它:

git checkout hello-world-images

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>

<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<p>A new line in our file!</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>

</body>
</html>

当初,咱们曾经实现了在该分支上的工作,能够为该分支暂存并提交:

git add --all
git commit -m "added new image"

咱们看到 index.html 在两个分支中都产生了更改。当初咱们筹备将 hello-world-images 合并到 master 中。然而,咱们最近在 master 中所做的更改会产生什么?

git checkout master
git merge hello-world-images

主动合并 index.html合并抵触(内容):index.html 中的合并抵触主动合并失败;解决抵触,而后提交后果。合并失败,因为在 index.html 的不同版本之间存在抵触。让咱们来查看状态:

git status

在 master 分支上,你有未解决的门路。

(解决抵触并运行 "git commit")

(应用 "git merge --abort" 停止合并)

要提交的更改:

新文件:img\_hello\_git.jpg

新文件:img\_hello\_world.jpg

未解决的门路:

(应用 "git add ..." 标记解决)

两者批改: index.html

这证实了 index.html 中存在抵触,但图像文件曾经筹备好并暂存以进行提交。因而,咱们须要解决抵触。在编辑器中关上文件:

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>

<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<<<<<<< HEAD

<p>This line is here to show how merging works.</p>

<p>A new line in our file!</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>

hello-world-images

</body>
</html>

咱们能够看到不同版本之间的差别,并依照咱们的需要进行编辑:
```html
<!DOCTYPE html><html><head><title>Hello World!</title><link rel="stylesheet" href="bluestyle.css"></head><body><h1>Hello world!</h1><div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div><p>This is the first file in my new Git Repo.</p><p>This line is here to show how merging works.</p><div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div></body></html>
```当初咱们能够暂存 index.html 并查看状态:
```bashgit add index.htmlgit status
```在 master 分支上,所有抵触都已解决,但你仍在合并中。(应用 "git commit" 实现合并)要提交的更改:新文件:img\_hello\_git.jpg新文件:img\_hello\_world.jpg批改:     index.html抵触已解决,咱们能够应用提交来实现合并:
```bashgit commit -m "merged with hello-world-images after fixing conflicts"
```而后删除 hello-world-images 分支:
```bashgit branch -d hello-world-images
```
```bash已删除分支 hello-world-images(是 1f1584e)。
```当初你对分支和合并的工作形式有了更好的理解。是时候开始与近程仓库一起工作了!## Git .gitignore 文件:创立、示例规定和模式匹配`.gitignore` 文件是用于指定 Git 疏忽的文件和文件夹的配置文件。这意味着 Git 不会跟踪或蕴含在版本控制中,但它们依然存在于你的工作目录中。以下是对于`.gitignore`文件的详细信息:创立\*\*`.gitignore`\*\*文件要创立一个`.gitignore`文件,请依照以下步骤操作:1.  关上终端或命令行工具。2.  导航到你的 Git 存储库的根目录。3.  创立`.gitignore`文件。你能够应用以下命令:`touch .gitignore`。这将在存储库的根目录中创立一个`.gitignore`文件。4.  应用文本编辑器关上`.gitignore`文件,你能够增加你要疏忽的文件和文件夹的规定。示例 `.gitignore` 文件上面是一个示例`.gitignore`文件的内容,演示了一些疏忽规定:
```log# 疏忽所有 .log 文件*.log# 疏忽任何名为 "temp" 的目录中的所有内容/temp/# 疏忽所有 .zip 和 .rar 压缩文件*.zip*.rar# 疏忽特定文件config.txt# 疏忽特定文件夹及其内容bin/build/
```这个`.gitignore`文件蕴含了各种疏忽规定,例如疏忽所有`.log`文件、名为"temp"的目录、`.zip`和`.rar`压缩文件、`config.txt`文件以及`bin/`和`build/`文件夹及其内容。`.gitignore` 文件的规定如下:-   模式匹配:`.gitignore`中的规定应用模式匹配来匹配文件和文件夹。-   行正文:以`#`结尾的即将被视为正文。-   文件匹配:你能够应用`*`来匹配任何字符,`?`来匹配单个字符,`[]`来匹配字符集,`[!...]`来否定字符集。-   目录匹配:如果模式以`/`结尾,则该模式仅匹配目录。-   递归匹配:应用``来匹配任何子目录。-   否定规定:应用`!`符号来否定已定义的规定。示例规定包含:-   `*.log`:疏忽所有扩大名为`.log`的文件。-   `/temp/`:疏忽名为"temp"的目录及其内容。-   `bin/`:疏忽名为"bin"的文件夹及其内容。-   `!important.log`:疏忽所有`.log`文件,但不包含名为"important.log"的文件。通过编辑`.gitignore`文件,你能够自定义哪些文件和文件夹应该被 Git 疏忽,以便它们不会蕴含在版本控制中。这对于防止将不必要的或敏感文件提交到版本控制中十分有用。## 最初为了不便其余设施和平台的小伙伴观看往期文章:微信公众号搜寻:`Let us Coding`,关注后即可获取最新文章推送看完如果感觉有帮忙,欢送 点赞、珍藏、关注