git 初始化git存储库_GIT:回顾我们的存储库

git 初始化git存储库

In this tutorial we will learn more about repositories like repository logs, making a commit in a repo, checking difference in commits etc.

在本教程中,我们将学习有关存储库的更多信息,例如存储库日志,在存储库中进行提交,检查提交中的差异等。

GIT:存储库日志 (GIT: Repository Logs)

Alright! So we now know a lot about Git and its commands. Git not only offers you a way to maintain your files, it also offers you tools to check out older versions of the files when the need arises. Before you begin, make sure all our files are available in your directory.

好的! 因此,我们现在对Git及其命令有了很多了解。 Git不仅为您提供了一种维护文件的方法,还为您提供了在需要时签出旧版本文件的工具。 在开始之前,请确保我们的所有文件都在您的目录中可用。

The first command we will be using is the git log which as you might expect, shows you a log of all your commits in your repository. The log command displays the most recent commits first. Scrolling down will show you the first commit that we added about out README file. Let's break down the output of this log.

我们将使用的第一个命令是git log ,正如您所期望的那样,它向您显示存储库中所有提交的日志。 log命令首先显示最近的提交。 向下滚动将显示您添加的关于README文件的第一次提交。 让我们分解一下该日志的输出。

Checking Repository Logs

It starts with a unique identifier for each commit. Recall that we discussed that that Git uses a SHA-1 hash for security. This is used as a unique identifier. You may think it is easier to name the commits numerically. While that is true, some repositories are public and have a large number of people contributing, so it gets difficult to number those commits as they occur.

它以每个提交的唯一标识符开头。 回想一下,我们讨论过Git使用SHA-1哈希来确保安全性。 这用作唯一标识符。 您可能认为用数字命名提交会更容易。 确实是这样,但是某些存储库是公共的,并且有大量人员参与其中,因此很难对这些存储进行编号。

Below the identifier is the Author name that initiated the commit. This makes it possible to keep track of who is contributing to your project. A little down below is that date time information regarding the commit.

标识符下面是发起提交的作者名称 。 这样就可以跟踪谁为您的项目做出了贡献。 以下是有关提交的日期时间信息。

And finally, we see the commit message itself. Notice that each message provides adequate information on what was done in that commit. Now consider a situation wherein you added a feature to your project but was dismissed by the client. With this log, you can check exactly when this feature was added and the commit identifier associated with it.

最后,我们看到提交消息本身。 注意,每个消息都提供了有关该提交中所做操作的足够信息。 现在考虑一种情况,其中您向项目中添加了功能,但被客户拒绝。 使用此日志,您可以准确检查何时添加了此功能以及与之关联的提交标识符。

GIT:检出提交 (GIT: Checkout a commit)

So now that you know when this feature was added. But how do you check out the code for that feature. Don't worry, we don't need an actual time machine to get that code. Git provides us with the functionality of actually going back in time and checking out that piece of code.

现在,您知道何时添加此功能。 但是,如何检查该功能的代码。 不用担心,我们不需要实际的时间机器来获取该代码。 Git为我们提供了实际回到过去并检出这段代码的功能。

Git uses the 'git checkout' command to recover an earlier version. For this, it requires the commit identifier. We don't actually have to type in the long hash value because let's face it, we are lazy. We just need the first 5-6 characters of the commit ID and we're good to go (most of the times).

Git使用“ git checkout”命令来恢复早期版本。 为此,它需要提交标识符。 实际上,我们不必键入长哈希值,因为我们很懒惰。 我们只需要提交ID的前5-6个字符,就可以了(大多数情况下)。

Uh-oh. A scary message. Something about being in a detached head state. Well Git is just telling you that you have checked out an earlier version of the file! Also making changes in here would probably be dangerous. Let's checkout our first commit. Go ahead and type ls. If you've followed the steps of the tutorial, you will probably see only the README file. Hmm. That's weird. There is no trace of the file, file2, file3.

哦哦 可怕的消息。 关于处于分离状态的东西。 Git只是告诉您,您已经签出了该文件的早期版本! 同样在此处进行更改可能很危险。 让我们检查一下我们的第一次提交。 继续输入ls 。 如果按照本教程的步骤进行操作,则可能只会看到README文件。 嗯 那真是怪了。 没有文件file2,file3的跟踪。

Checking out a commit

Before we freak out over it, let's understand that we are checking out an older version of the repository. When we initiated commit for the first time, we did not have file, file2, file3 at all! This explains the absence of those files.

在迷惑它之前,让我们了解一下,我们正在检查存储库的旧版本。 首次启动提交时,我们根本没有文件,file2,file3! 这解释了这些文件的缺失。

GIT:检查提交差异 (GIT: Checking difference in commits)

So let's get back to the present. We can use the 'git checkout' again, but where do we get back to? If you remember the 'git status' command, it showed a message 'on branch master'.

Running the following command will bring you back to the current repository state:

现在让我们回到现在。 我们可以再次使用'git checkout' ,但是我们又回到哪里呢? 如果您还记得'git status'命令,它会显示一条消息'on branch master'

运行以下命令将使您返回到当前存储库状态:
$ git checkout master

Type in ls again to make sure all your files are available. We have another method to check out older versions. The git diff comes in handy. It shows the differences between the two states. Just run the command with the identifier of the first commit and the last commit. Skip the first few lines in the output. Check the + sign which means content was added. It then proceeds to show the actual changes.

再次输入ls以确保所有文件都可用。 我们还有另一种方法可以签出旧版本。 git diff派上用场了。 它显示了两种状态之间的差异。 只需运行带有第一次提交和最后一次提交的标识符的命令即可。 跳过输出中的前几行。 选中+ sign ,表示已添加内容。 然后继续显示实际更改。

Checking difference in commits

There are graphical interfaces which are much clearer and easier to use, but this is the basic of it. That was all about the Git basics. Let's dive in deeper, shall we?

图形界面更加清晰易用,但这是基础。 这就是所有关于Git的基础知识。 让我们深入一点,对吧?

翻译自: https://www.studytonight.com/github/more-about-repository-in-git

git 初始化git存储库

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值