让你爱上 Git 的 10 篇文章
Git

> 
> 你对 Git 了解得越多，使用 Git 就会越容易。一起来回顾下年度最佳 Git 文章。
> 
> 
> 


![](/data/attachment/album/202101/04/120824ue7jvn9nj4n2s4vh.jpg)


Git 是开源开发者工具箱中最基本的工具。这个强大的版本控制系统有很多复杂的功能。使用 Git 不需要了解它所有的功能，但是对 Git 了解得越多，使用 Git 就会越容易。


下面每篇文章都提供了一些奇技淫巧来提升和增强你的 Git 技能。


### 怎么解决 git 合并时的冲突


Brian Breniser 的这篇教程从 `git merge` 的定义以及解释什么是冲突开始。然后他详细解释了在合并时如果有冲突[如何解决冲突](https://opensource.com/article/20/4/git-merge-conflict)。Breniser 还提了一些能学习更多关于解决冲突和其他 Git 功能的建议。


### 4 个不可或缺的 Git 脚本


Vince Power 分享了他[最重要的 Git 脚本](/article-12180-1.html)。这些脚本可以从 Git Extras 包中获得，该包提供了 60 多个 Git 增强脚本。Power 最爱的脚本有：在无需打开文本编辑器的情况下编辑 `.git-ignore` 的 `git-ignore` ；用于提供 Git 仓库的摘要的 `git-info`；用来处理 GitLab 的合并请求（MR）和 GitHub 的拉取请求（PR）的 `git-pr`；把 Git 的提交（`commit`）、标签（`tag`）和推送（`push`）合为一体的 `git-release`。


### 完美生活：git rebase -i


在 Dave Neary 的这篇文章中可以学习[使用 git rebase -i 来修改你的 Git 提交历史](/article-12231-1.html)。Neary 从解释 Git 是如何把提交历史记录到仓库中的以及 `git commit` 和 `git rebase` 的区别。之后，他又解释了如何使用 `git rebase -i` 让 Git 仓库的提交历史变得简洁。这个命令能让你把“修复书写错误”的提交合进其它提交里，把几个相似的小提交合并成一个大的提交。


### Git Cola 让使用 Git 变得简单


Seth Kenlon 演示了[如何使用 Git Cola](https://opensource.com/article/20/3/git-cola)。Git 是个命令行工具，这对于有些人来说是有学习门槛的。Git Cola 提供了一个图形界面，因此不习惯用命令行的用户也可以使用 Git。在此文中，Kenlon 展示了如何安装 Git Cola，并使用 Git Cola 的图形用户界面完成了很多 Git 提交任务。


### 6 个在团队中使用 Git 的最佳实践


从设计上讲，Git 是个协同工具，但是关于如何协同的很多细节是由团队自行决定的。Ravi Chandran 提了一些建议，团队应该采用这些建议[更高效地使用 Git](/article-12621-1.html)。Chandran 在文中列出的 6 个最佳实践是：“使约定正式化”，“正确地合并修改”，“经常变基你的功能分支”，“在合并之前把压扁你的提交”，“使用标签”，“让软件的可执行程序打印标签”。


### 改变我使用 Git 工作方式的七个技巧


Rajeev Bera 分享了 [7 个 Git 技巧](/article-12894-1.html)，这些技巧能提升 Git 的用户体验。文章探讨了 Git 的自动更正、提交计数、仓库优化、备份未追踪的文件、了解 `.git` 目录、在另一个分支查看文件以及在 Git 下搜索。


### 使用 tmux 和 Git 定制化我的 Linux 终端


Moshe Zadka 展示了他是如何[使用 tmux 和 Git](/article-12450-1.html)定制化他的 Linux 终端的。Zadka 的文章是个人工作流的优秀探索。他使用 GNOME 终端，用 tmux 和一些能让他快速查看 Git 仓库状态的功能来增强终端。他只需要用一个字母就可以提交文件或把提交推送到远程仓库。


### 使用 Lazygit 让复杂的 Git 任务简单化


Jesse Duffield 解释了如何使用[Lazygit，一个能让使用 Git 变得简单的终端界面](https://opensource.com/article/20/3/lazygit)。Lazygit 的开发者 Duffield 详细阐述了如何使用这个界面来暂存文件、以交互方式变基、进行筛选、搜索提交以及创建一个 PR。


### 使用子模块和子树来管理 Git 项目


子模块和子树是两种在 Git 仓库中引入嵌套的子项目的方式。在[使用子模块和子树来管理 Git 项目](/article-12244-1.html)中，Manaswini Das 解释了两个选项的工作原理和区别。


### 不喜欢 diff？那么试试 Meld


Ben Nuttall 展示了如何[使用 Meld 代替 diff](/article-12067-1.html)来进行对比和合并修改。Meld 是图形化的 `diff`，输出更容易理解。Nuttall 演示了使用 `diff` 和 Meld 进行对比的区别。他还解释了 Meld 是如何识别 Git 项目的，这意味着在 Git 中一个文件被提交之后，可以用 Meld 来搜索修改。


你想学习关于 Git 的什么内容？请在评论去分享你的想法。




---


via: <https://opensource.com/article/20/12/git>


作者：[Joshua Allen Holm](https://opensource.com/users/holmja) 选题：[lujun9972](https://github.com/lujun9972) 译者：[lxbwolf](https://github.com/lxbwolf) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Git is an essential tool in the open source developer's toolkit. This powerful version-control system has a lot of complex features. Not all of the features are necessary to use Git, but knowing more about how Git works makes working with Git easier.

During 2020, Opensource.com published many excellent articles about Git, including the top 10 covered below. Each article provides tips and tricks for improving and enhancing your Git experience.

## How to resolve a git merge conflict

This tutorial by Brian Breniser begins by defining `git merge`

and explaining what merge conflicts are. Then he provides a detailed tutorial about how to [work through a merge conflict](https://opensource.com/article/20/4/git-merge-conflict) when one arises. Breniser also provides a few suggestions for where you can go to learn more about resolving merge conflicts and other Git functions.

## 4 Git scripts I can't live without

Vince Power shares his [most important Git scripts](https://opensource.com/article/20/4/git-extras). These scripts come from the Git Extras package, which provides over 60 scripts for enhancing Git. Power's favorite scripts are `git-ignore`

for editing `.git-ignore`

without opening a text editor; `git-info`

for providing a summary about a Git repository; `git-mr`

and `git-pr`

for dealing with merge requests on GitLab and pull requests on GitHub; and `git-release`

, which combines Git's `commit`

, `tag`

, and `push`

into a single command.

## The life-changing magic of git rebase -i

Learn how to use [git rebase -i to revise your Git history](https://opensource.com/article/20/4/git-rebase-i) in this article by Dave Neary. Neary starts by explaining how Git handles the history of commits to a repository and the differences between `git commit`

and `git rebase`

. Next, he explains how to use `git rebase -i`

to alter the history of a Git repository to make things cleaner. This allows you to move changes from "fixed typo" commits into other commits and merge similar smaller commits into combined larger commits.

## Make Git easy with Git Cola


Opensource.com editor Seth Kenlon demonstrates [how to use Git Cola](https://opensource.com/article/20/3/git-cola). Git is a command-line tool, which might turn some people off from using it. Git Cola provides a graphical interface to Git, so users who are not comfortable working on the command line can still take advantage of Git's features. In this article, Kenlon shows how to install Git Cola and accomplish many Git commit tasks using Git Cola's graphical user interface.

## 6 best practices for teams using Git

By design, Git is a collaborative tool, but many of the specifics about how to collaborate are left up to teams to decide. Ravi Chandran provides suggestions that any team could adopt [to use Git more effectively](https://opensource.com/article/20/7/git-best-practices). The six best practices, which Chandran explains in the article, are "formalize Git conventions," "merge changes properly," "rebase your feature branch often," "squash commits before merging," "use tags," and "make the software executable print the tag."

## 7 Git tricks that changed my life

Rajeev Bera shares [seven Git tricks](https://opensource.com/article/20/10/advanced-git-tips) that improve the user experience when working with Git. The article explores Git's autocorrect option, counting commits, repo optimization, backing up untracked files, knowing the `.git`

folder, viewing a file on another branch, and searching in Git.

## Customizing my Linux terminal with tmux and Git

Moshe Zadka demonstrates how he [used tmux and Git](https://opensource.com/article/20/7/tmux-git) to customize his Linux terminal. Zadka's article is a fascinating exploration of one person's workflow. He uses GNOME Terminal but enhances it by using tmux and features that allow him to see the status of a Git repository quickly. If files need to be committed or a commit needs to be pushed, a single letter indicates that.

## Make advanced Git tasks simple with Lazygit

Jesse Duffield explains how to use [Lazygit, a terminal interface that makes using Git easier](https://opensource.com/article/20/3/lazygit). Duffield, who developed Lazygit, details how to use the interface to stage files, rebase interactively, do cherry-picking, search through commits, and open a pull request.

## Managing Git projects with submodules and subtrees

Submodules and subtrees are two different ways to include nested subprojects in a Git repository. In [ Managing Git projects with submodules and subtrees](https://opensource.com/article/20/5/git-submodules-subtrees), Manaswini Das explains how the two options work and how they differ.

## Don't love diff? Use Meld instead

Ben Nuttall shows how to [use Meld instead of diff](https://opensource.com/article/20/3/meld) to compare and merge changes. Meld is a graphical alternative to `diff`

with output that is easier to understand. Nuttall demonstrates the difference between comparing two files using `diff`

and Meld. He also explains how Meld is Git-aware, which means it can be used to explore changes made to a file since the last time it was committed in Git.

What do you want to learn about Git? Please share your ideas in the comments, and if you have knowledge to share, please [consider writing about it for Opensource.com](https://opensource.com/how-submit-article).

## Comments are closed.