git教学指南_完整的Git指南
git教学指南
Git is a free and Open Source version control system (VCS), a technology used to track older versions of files, providing the ability to roll back and maintain separate different versions at the same time.
Git是⼀个免费的开源版本控制系统 (VCS),该技术⽤于跟踪⽂件的较早版本,提供了同时回滚和维护单独的不同版本的能⼒。
Git is a successor of SVN and CVS, two very popular version control systems of the past. First developed by Linus Torvalds (the creator of Linux), today is the go-to system which you can’t avoid if you make use of Open Source software.
Git是SVN和CVS(过去两个⾮常流⾏的版本控制系统)的继承者。 最初由Linus Torvalds(Linux的创建者)开发,如今已成为使⽤系统,如果您使⽤开放源代码软件,您将⽆法避免该系统。
分布式VCS (Distributed VCS)
Git is a distributed system. Many developers can clone a repository from a central location, work indep
endently on some portion of code, and then commit the changes back to the central location where everybody updates.
Git是⼀个分布式系统。 许多开发⼈员可以从中央位置克隆存储库,在代码的某些部分独⽴⼯作,然后将更改提交回每个⼈都更新的中央位置。
Git makes it very easy for developers to collaborate on a codebase simultaneously and provides tools they can use to combine all the independent changes they make.
Git使开发⼈员可以轻松地同时在代码库上进⾏协作,并提供了可⽤于组合他们所做的所有独⽴更改的⼯具。
A very popular service that hosts Git repositories is , especially for Open Source software, but we can also mention BitBucket, GitLab and many others which are widely used by teams all over the world to host their code publicly and also privately.
托管Git存储库的⼀种⾮常流⾏的服务是 ,尤其是对于开源软件,但是我们还可以提及BitBucket,GitLab和许多其他⼯具,它们被全世界的团队⼴泛使⽤以公开和私有地托管其代码。
如何安装Git (How to install Git)
Installing Git is quite easy on all platforms:
在所有平台上安装Git都很容易:
OSX (OSX)提交更改是什么
Using , run:
使⽤ ,运⾏:
brew install git
视窗 (Windows)
Download and install .
下载并安装 。
的Linux (Linux)
Use the package manager of your distribution to install Git. E.g.
使⽤发⾏版的软件包管理器来安装Git。 例如
sudo apt-get install git
or
要么
sudo yum install git
如何初始化存储库 (How to initialize a repository)
Once Git is installed on your system, you are able to access it using the command line by typing git.在您的系统上安装Git之后,您可以通过输⼊git使⽤命令⾏来访问它。
Suppose you have a clean folder. You can initialize a Git repository by typing
假设您有⼀个⼲净的⽂件夹。 您可以通过键⼊以下内容来初始化Git存储库
git init
What does this command do? It creates a .git folder in the folder where you ran it. If you don’t see it, it’s because it’s a hidden folder, so it might not be shown everywhere, unless you set your tools to show hidden folders.
该命令的作⽤是什么? 它在运⾏它的⽂件夹中创建⼀个.git⽂件夹。 如果您看不到它,那是因为它是⼀个隐藏⽂件夹,因此除⾮您设置⼯具来显⽰隐藏⽂件夹,否则它可能不会在所有地⽅显⽰。
Anything related to Git in your newly created repository will be stored into this .git directory, all except the .gitignore file, which I’ll talk about in the next article.
新创建的存储库中与Git相关的所有内容都将存储在此.git⽬录中,除了.gitignore⽂件外,所有⽂件都
将存储在该⽂件中,我将在下⼀篇⽂章中讨论该⽂件。
如何将⽂件添加到存储库 (How to add files to a repository)
Let’s see how a file can be added to Git. Type:
让我们看看如何将⽂件添加到Git。 类型:
echo "Test" >
to create a file. The file is now in the directory, but Git was not told to add it to its index, as you can see what git status tells us:
创建⼀个⽂件。 该⽂件现在位于⽬录中,但是并未告知Git将其添加到索引中,因为您可以看到git status告诉我们:
将⽂件添加到暂存区 (Add the file to the staging area)
We need to add the file with
我们需要添加⽂件
git
to make it visible to Git, and be put into the staging area:
使它对Git可见,并放⼊暂存区域 :
Once a file is in the staging area, you can remove it by typing:
⼀旦⽂件位于暂存区中,您可以通过键⼊以下内容将其删除:
git
But usually what you do once you add a file is commit it.
但是通常在添加⽂件后执⾏的操作就是提交它。
如何提交变更 (How to commit changes)
Once you have one or more changes to the staging area, you can commit them using ⼀旦您对暂存区进⾏了⼀个或多个更改,就可以使⽤
git commit -am "Description of the change"
This cleans the status of the staging area:
这将清理暂存区的状态:
and permanently stores the edit you made into a record store, which you can inspect by typing git log:
并将您所做的修改永久存储到记录存储中,您可以通过输⼊git log进⾏检查:
分⾏ (Branches)
When you commit a file to Git, you are committing it into the current branch.
将⽂件提交到Git时,就是将其提交到当前分⽀中。
Git allows you to work simultaneously on multiple, separate branches, different lines of development which represent forks of the main branch.
Git允许您在多个独⽴的分⽀上同时⼯作,这些不同的开发线代表主分⽀的分⽀。
Git is very flexible: you can have an indefinite number of branches active at the same time, and they can be developed independently until you want to merge one of them into another.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论