Git –提交对存储库的更改

Previous chapter we have created our new clean repository but we did not added any code. In this chapter we will add some code and create some revision or versions of the code.

在上一章中,我们创建了新的干净存储库,但未添加任何代码。 在本章中,我们将添加一些代码并创建一些版本的代码。

获取存储库状态 (Getting Status of Repository)

As we stated before we have a clean repository we can check this.

如前所述,我们有一个干净的存储库,我们可以检查一下。

$ git status 
On branch master 
 
Initial commit 
 
nothing to commit (create/copy files and use "git add" to track)

As we see status command provides some brief information about repository. We are on the master branch. We will look branches in the future. We have nothing to commit. Sure we have not added anything for now.

如我们所见, status命令提供了有关存储库的一些简要信息。 我们在master分支上。 将来我们会寻找分支机构。 我们没有什么可承诺的。 当然,我们暂时还没有添加任何东西。

将文件添加到修订版 (Adding Files to the Revision)

Git have some fundamental steps to commit. We will look them through writing our app. Below we can find the natural flow of a commit.

Git有一些基本步骤可以落实。 我们将通过编写我们的应用程序来查找它们。 在下面我们可以找到提交的自然流程。

工作副本 (Working Copy)

We will create our app with the following code.

我们将使用以下代码创建我们的应用。

$ echo 'print("Hello Poftut")' > main.py

We have created a file main.py with single line code.

我们用单行代码创建了文件main.py

查看变更 (Review Changes)

We have added some code to our project and want to see status of working copy. Working copy is currently used snapshot of the files.

我们已经在项目中添加了一些代码,并希望查看工作副本的状态。 工作副本是当前使用的文件快照。

$ git status 
On branch master                                                                                                                      
                                                                                                                                      
Initial commit                                                                                                                        
                                                                                                                                      
Untracked files:                                                                                                                      
  (use "git add <file>..." to include in what will be committed)                                                                      
                                                                                                                                      
        main.py                                                                                                                       
                                                                                                                                      
nothing added to commit but untracked files present (use "git add" to track)

As we see mail.py is under untracked files. Untracked file is a files that is not added to the commit operation. So If we want to commit our file we should add main.py into tracked files.

如我们所见,mail.py位于未跟踪的文件下。 未跟踪的文件是未添加到提交操作的文件。 因此,如果要提交文件,则应将main.py添加到跟踪的文件中。

$ git add main.py  
$ git status 
On branch master 
 
Initial commit 
 
Changes to be committed: 
  (use "git rm --cached <file>..." to unstage) 
 
        new file:   main.py

We have added main.py file to the tracking files. After adding file if we look to the status of working directory we can see that main.py is tagged as new file and there is no other untracked file.

我们已经将main.py文件添加到跟踪文件中。 添加文件后,如果我们查看工作目录的状态,我们可以看到main.py被标记为新文件,并且没有其他未跟踪的文件。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值