git安装git flow
This post isn’t going to explain theoretical concepts behind Git — a version-control system usually managed from the command line, though sometimes managed from a GUI (if we’re Windows programmers, which is me, sometimes). Neither is this a post with in-depth insights or sophisticated actions that can be done in Git and nor is it a post that explains Git and GitHub to non-programmers.
这篇文章不会解释Git背后的理论概念。Git是一个版本控制系统,通常是通过命令行进行管理的,尽管有时是通过GUI进行管理的(如果我们是Windows程序员,有时就是我)。 这既不是具有深入见解或可以在Git中完成的复杂动作的帖子,也不是向非程序员介绍Git和GitHub的帖子。
Then what is this? It’s a post in which I gathered basic Git settings that I apply when setting up Git on a new server. This will be my — and hopefully your — one-stop-shop for Git initial configuration definitions.
那这是什么 在这篇文章中,我收集了在新服务器上设置Git时应用的基本Git设置。 这将是我(也希望是您)一站式购买Git初始配置定义的过程。
安装 (Installation)
Let’s start at the beginning — installing Git on a server. Every operating system has its own way of installing Git. Atlassian has a post on its website that lists all the methods for all OSs — Mac, Windows, Linux — and their various flavors. On Centos, which is what’s relevant to me, here is how to install:
让我们从头开始-在服务器上安装Git。 每个操作系统都有自己的Git安装方式。 Atlassian在其网站上发布了一篇文章 ,列出了适用于所有操作系统(Mac,Windows,Linux)的所有方法以及它们的各种风格。 在Centos上,与我相关的是以下安装方法:
sudo yum install git
sudo yum install git
配置Git用户定义 (Configuring the Git User Definitions)
Every commit is attributed to a specific user. It is recommended that the user’s username and email be set immediately after installation. This is to prevent this message from appearing on the first commit:
每个提交都归属于特定用户。 建议在安装后立即设置用户名和电子邮件。 这是为了防止在第一次提交时出现此消息:
Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
Setting username and password:
设置用户名和密码:
git config --global user.name "Your Name"
git config --global user.name "Your Name"
git config --global user.email you@example.com
git config --global user.email you@example.com
If you want to fix the username and password that were used in the commit, you do it using the --amend
parameter:
如果要修复提交中使用的用户名和密码,请使用--amend
参数来完成:
git commit --amend --author='Your Name <you@example.com>'
git commit --amend --author='Your Name <you@example.com>'
色彩 (Colors)
Git can paint its commands’ output in beautiful, easy to read colors, instead of just white:
Git可以用漂亮,易于阅读的颜色而不是白色来绘制其命令的输出:
The easiest way to make this happen is by using running this configuration in the command line:
实现此目的的最简单方法是在命令行中运行以下配置:
git config --global color.ui auto
git config --global color.ui auto
If you want to further enhance it, you can read this answer on unix.stackexchange.
如果要进一步增强它,可以在unix.stackexchange上阅读此答案。
自动完成 (Automatic Completions)
Why write full commands if you can have the computer auto-complete? To accomplish this, you can install the bash-completion
package:
如果可以自动完成计算机,为什么还要编写完整的命令? 为此,您可以安装 bash-completion
软件包 :
sudo yum install git bash-completion
lg Alias (The lg Alias)
The git log
command’s default output includes the commit’s full hash number, the full date, the commiter’s name — each of them on its own row — and they are all displayed with more or less the same colors.
git log
命令的默认输出包括提交的完整哈希数,完整日期,提交者的名称(它们每个都位于其自己的行中),并且它们都以或多或少相同的颜色显示。
This is wasteful in terms of space, and colorless.
就空间而言这是浪费的,并且是无色的。
Here the lg
command comes to the rescue — so that it is possible to have each commit take up just one line, with color separation for the hash number, user name, and time. Another advantage of using git lg
is that that it presents the time in a friendlier way — it displays how long ago it was, rather than an absolute date and time.
此处使用lg
命令可以解决问题-从而使每次提交仅占用一行,并且散列号,用户名和时间进行颜色分隔是可能的。 使用git lg
另一个优点是,它以一种更友好的方式显示时间-它显示了多长时间,而不是绝对的日期和时间。
To achieve this, write this command in the command line:
为此,请在命令行中编写以下命令:
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
And the result will be concise and colorful:
结果将简洁明了:
告诉Git Diff忽略唯一区别在于权限的文件 (Tell Git Diff to Ignore Files Whose Only Difference Is Permissions)
One of the annoying things that could happen with Gi is that when asking for git status
, you get a list of files that are supposedly changed, only to find out when diffing them that file permissions is the only update on them.
Gi可能发生的一件令人烦恼的事情是,当询问git status
,您会得到一个据称已更改的文件列表,只是在与它们进行区分时才发现文件权限是对其的唯一更新。
To prevent that, tell git to ignore file mode:
为了防止这种情况,请告诉git忽略文件模式:
git config core.filemode false
提交讯息 (Commit Messages)
A guide, with demonstrations of good and bad, to writing helpful commit messages.
编写有益的提交消息的指南,包括好坏的演示。
有时Git Diff没有显示差异 (Sometimes Git Diff Does Not Show Differences)
It’s not clear why this happens, but sometimes we know there are differences, and git status tells us that the file is supposedly modified, but when you run git diff
on it, nothing is returned.
目前尚不清楚为什么会发生这种情况,但是有时我们知道存在差异,并且git status 告诉我们该文件应该被修改了,但是当您对它运行git diff
时,什么也不会返回。
It’s weird, strange, and un-understandable, and I, therefore, had to overcome it. Fortunately, I found an answer in SO that worked, doing the following workflow:
这很奇怪,奇怪且难以理解,因此我不得不克服它。 幸运的是,我通过执行以下工作流程在SO中找到了有效的答案 :
Add the file:
添加文件:
Add the file:
git add file_name
添加文件:
git add file_name
Then write:
然后写:
Then write:
git diff — cached file_name
然后写:
git diff — cached file_name
That will show you the differences between the previous version and this one.
这将向您显示以前版本与本版本之间的区别。
分词 (Parting Words)
What about you? Do you also have basic definitions — of Git or anything else interesting — that you can not live without? I’ll be more that happy to hear about them! Thanks for reading, I hope that you found my article helpful.
你呢? 您是否还拥有Git或其他有趣的基本定义? 我会很高兴听到他们的消息! 感谢您的阅读,希望您对我的文章有所帮助。
-This post was originally posted on my blog (Hebrew).
-此帖子最初发布在我的博客 (希伯来语)上。
翻译自: https://codeburst.io/git-installation-and-basic-definitions-f505db8aa3fd
git安装git flow