在Ubuntu 16.04上安装和配置Git
Git是一个开源,分布式版本控制系统,旨在处理从小到大的每种类型的项目,速度和效率。
很容易学习并具有闪电速度性能的低记忆消耗。
它超越了诸如Subversion,CVS,Perforce和ClearCase等其他其他SCM工具,其具有廉价的本地分支,方便的临时区域和多个工作流等功能。
此外,Git 2.9.0有各种功能和错误修复与剩余的版本相比,Git 2.9的一些高级功能使其突出的休息如下:
- 更快,更灵活的子模块:它为克隆和更新的子模块并行带来支持。
- 美丽的Diff Usages:它为差异处理增加了一个新的实验启发式。
- 测试提交Git Interactive Rebase
Git对他人的优点SCM工具
- 分支和合并
- 小而快
- 分散式
- 数据保证
- 分期区
- 免费和opensource.
在本文中,我将演示如何在Ubuntu 16.04服务器上安装最新的Git版本。
让我们从安装步骤开始。
安装git
在Ubuntu服务器上,我们只需运行此命令就可以从其存储库中安装Git软件包。
root@ubuntu:~# apt-get update root@ubuntu:~# apt-get install git
但是,我们通过安装方式获得最新的Git发布包并不是强制性的。
在这种情况下,我们更愿意通过从源包下载来安装Git。
我们可以在此处下载我们的Git发布包。
我将解释我在系统上安装最新的Git 2.9.0版本的步骤。
下载git文件
第1步:从上面的下载链接下载Git 2.9包
root@ubuntu:~# wget https://github.com/git/git/archive/v2.9.0.zip root@ubuntu:~# unzip v2.9.0.zip
如果刚刚运行此命令"apt安装解压缩",则安装解压缩模块如果它不存在于服务器中。
配置和构建
步骤2:移动到提取的GIT文件夹并开始配置。
首先,我们需要进行配置并构建GIT包。
Inorder要使配置部分工作,我们需要在我们的服务器中安装AutoConf。
root@ubuntu:~/git-2.9.0# apt-get install autoconf root@ubuntu:~/git-2.9.0# make configure GEN configure root@ubuntu:~/git-2.9.0# ./configure --prefix=/usr/local
安装AutoConf后,我们可以创建GIT的配置文件,并使用上面的命令开始配置。
但在配置时间期间,如果我们遇到类似的错误,请安装以下包。
Error: configure: error: in `/root/git-2.9.0': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details Fix : root@ubuntu:~/git-2.9.0# apt-get install gcc
我们可以安装GCC软件包以在服务器上启用C编译器,并将配置部分顺利地完成。
root@ubuntu:~/git-2.9.0# ./configure --prefix=/usr/local checking for BSD sysctl... no checking for POSIX Threads with ''... no checking for POSIX Threads with '-mt'... no checking for POSIX Threads with '-pthread'... yes configure: creating ./config.status config.status: creating config.mak.autogen config.status: executing config.mak.autogen commands
我们的下一步是构建Git包。
我们仍然可以通过运行此制作命令构建包。
root@ubuntu:~/git-2.9.0# make prefix=/usr/local PS : At times, you Jan come across some errors while running this, due to some missing packages. Errors : root@ubuntu:~/git-2.9.0# make prefix=/usr/local CC credential-store.o In file included from credential-store.c:1:0: cache.h:40:18: fatal error: zlib.h: No such file or directory compilation terminated. Makefile:1935: recipe for target 'credential-store.o' failed make: *** [credential-store.o] Error 1 /bin/sh: 1: msgfmt: not found Makefile:2094: recipe for target 'po/build/locale/pt_PT/LC_MESSAGES/git.mo' failed make: *** [po/build/locale/pt_PT/LC_MESSAGES/git.mo] Error 127
为了纠正这些错误,我们可以安装Git所需的以下包。
apt-get install zlib1g-dev apt-get install tcl-dev apt-get install libssl-dev apt-get install gettext
修复这些错误后,我们可以重新运行这些make命令以完成构建过程。
root@ubuntu:~/git-2.9.0# make prefix=/usr/local root@ubuntu:~/git-2.9.0# make prefix=/usr/local install
现在我们可以确认我们的Git安装。
我们可以通过运行ldconfig设置从/usr/local获取git库的环境变量。
root@ubuntu:~# git version git version 2.9.0
git设置
Git附带一个名为Git Config的工具,允许我们获取并设置配置变量,控制Git如何工作的所有方面。
这些变量可以存储在三个不同的地方:
/etc/gitconfig文件:此文件包含系统上每个用户和所有存储库的值。
git config --system:此选项将专门从此文件中读取和写入。~/.gitconfig或者~/.config/git/config文件:此文件特定于每个user.git config - global:此选项将读取并在此文件中写入我们当前使用的任何存储库的GIT目录中的git/config:config文件。此文件特定于该单个Repository.git config -local:此选项将专门从此文件中读取和写入。创建身份
首先,我们需要在Git安装后要做的是身份。
我们需要设置用户名和电子邮件地址。
这是重要原因,因为Git Commit使用此信息,并且它不可思议地添加到我们创建的提交中。
root@ubuntu:~# git config --global user.name "Saheetha Shameer" root@ubuntu:~# git config --global user.email [email protected]
检查git设置
我们可以使用命令git config -list来检查当前的git设置。
这将列出所有GIT设置。
root@ubuntu:~# git config --list user.name=Saheetha Shameer [email protected]
我们还可以通过键入这样的特定键值来检查状态
root@ubuntu:~# git config user.name Saheetha Shameer
git命令
通过运行Git帮助命令,我们可以获得更多关于GIT命令的信息。
以下是一些常见的git命令及其用途。
通过运行此命令Git帮助配置,我们可以获得Git手册页面。
创建和管理GIT存储库
首先,让我们看看如何创建Git存储库。
我们可以在现有文件夹上运行此命令以在现有文件夹上创建Git存储库。
我创建了一个名为gitdemo的文件夹,并启动了命令git init以创建我的存储库。
root@ubuntu:~# mkdir gitdemo root@ubuntu:~# cd gitdemo/ root@ubuntu:~/gitdemo# root@ubuntu:~/gitdemo# git init Initialized empty Git repository in /root/gitdemo/.git/
执行此命令后,我们可以看到它创建一个名为.git的文件夹。
这是Git存储一切,包括更改集,分支等。
让我们看看这个文件夹的结构。
随时我们可以删除此文件夹以销毁存储库。
简而言之,这个意味着git使用本地文件库设置,我们可以其中拍摄此文件夹的手动备份以保存或者提交到任何远程存储库或者甚至将这些备份文件发送给朋友,以便在安装的git直接访问存储库在他们的系统中。
此时,我们没有任何东西可以在版本控制下进行,因此让我们创建一个文件并检查Git状态。
root@ubuntu:~/gitdemo# touch testrepo.txt root@ubuntu:~/gitdemo# git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) testrepo.txt nothing added to commit but untracked files present (use "git add" to track)
即使存在testRepo.txt存在的文件,它也尚未被Git跟踪。
Git状态告诉我们,我们的文件未经触发。
我们需要通过命令git添加<filename>来解决此问题。
root@ubuntu:~/gitdemo# git add testrepo.txt root@ubuntu:~/gitdemo# git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: testrepo.txt
现在我们的Git状态显示,因为我们的测试文件已准备好提交。
这称为分期。
我们已向此文件进行了提交。
在进行repo之前,我们需要启动git add命令以更新所有更改。
例如,如果我们在我们的测试文件中修改任何内容,那么在我们再次运行此Git add命令之前,不会添加提交的更改。
Git状态将识别修改。
root@ubuntu:~/gitdemo# git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: testrepo.txt Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: testrepo.txt
因此,我们需要运行git add命令才能阶段这些更改。
root@ubuntu:~/gitdemo# git add testrepo.txt root@ubuntu:~/gitdemo# git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: testrepo.txt
一旦我们阶段更改,我们就准备好将它们提交给我们的存储库。
我们可以使用Git Commit命令。
通过运行此命令"git commit testRepo.txt",它将显示一个Vim窗口,我们需要在屏幕顶部键入"初始提交"并保存到退出。
root@ubuntu:~/gitdemo# git commit testrepo.txt [master (root-commit) 2b3f303] Initial commit 1 file changed, 2 insertions(+) create mode 100644 testrepo.txt PS : you can even use git commit -m "changes" instead
如果我们再次运行git状态,我们可以看到没有更多的待处理更改,这意味着它们都致力于我们的存储库。
root@ubuntu:~/gitdemo# git status On branch master nothing to commit, working directory clean
我们可以通过运行git log来获取我们提交历史记录的详细信息,该日志将提供他们的详细信息,如作者,时间,日期,提交指标等。
root@ubuntu:~/gitdemo# git log commit 2b3f30387f3b7417acbbc5287132df7441aa0881 Author: Saheetha Shameer <[email protected]> Date: Thu May 14 08:02:52 2015 +0000 Initial commit