Git combat (3)--Submit to local repository

Source: Internet
Author: User
Tags touch command version control system

The previous section mentioned the concept of the warehouse, in fact, after initializing git, git divides the local space into two parts, part of the workspace (working directory), the Studygit directory is the workspace to store our own files, and the other is the repository (Repository), also known as a warehouse , has a. git hidden directory in the workspace directory that is not part of the workspace or repository.

[Email protected]$ ls-al
Total 0
Drwxr-xr-x 3 Houenxun Staff 102 7 9 19:18.
drwxr-xr-x+ Houenxun Staff 1768 7 9 19:18..
Drwxr-xr-x Houenxun Staff 340 7 9 19:20. git

With git status We can view the status of the current warehouse in real time

[Email protected]$ git status
On Branch Master

Initial Commit

Nothing-to-commit (create/copy files and use "Git add" to track)

Currently in the Master branch, and nothing needs to be committed, we create a file in the workspace with the Touch command and view the warehouse information again

[Email protected]$ Touch Readme.txt
[Email protected]$ git status
On Branch Master

Initial Commit

untracked files:
(use "git add <file> ..." to include in what'll be committed)

Readme.txt

Nothing added to commits but untracked files present (use "Git add" to track)

untracked file indicates that Readme.txt is a new document and has no version information in the repository. Below we will submit the Readme.tex to the local repository.

[Email protected]$ git add readme.txt
[Email protected]$ git commit-m "commit readme.txt"
[Master (root-commit) 32a7706] Commit readme.txt
1 file changed, 0 insertions (+), 0 deletions (-)
Create mode 100644 readme.txt
[Email protected]$

There may be a problem here, submit the local repository, why do the add operation before committing the commit operation?

In fact, Git's warehouse further divided a temporary storage area (stage), through the Add command just to submit the file to the stage, similar to save the draft.


Now look at the git status

[Email protected]$ git status
On Branch Master
Nothing-to-commit, working directory clean

There are currently no files to submit. If you want to view the commit record using git log

[Email protected]$ git log
Commit 32A7706DF9F266522BDB223E8F4308CFCCEC01BA
Author:houenxun <[email protected]>
Date:thu Jul 9 20:08:48 2015 +0800

Commit Readme.txt

Where 32A7706DF9F266522BDB223E8F4308CFCCEC01BA represents the unique ID of the commit operation

[Email protected]$ touch Hello Test test2
[Email protected]$ ls
Helloreadme.txttesttest2
[Email protected]$ git add *
[Email protected]$ git status
On Branch Master
Changes to be committed:
(use "Git reset HEAD <file> ..." to Unstage)

New File:hello
New File:test
New File:test2


Here we create multiple files at once, add to staging area with git add and look at the status of the current warehouse! It is also necessary to note that Git add can add more than one file at a time, either in the form of Git file1 file2 or by matching multiple files with wildcards!

[Email protected]$ git commit-m "Hello Test test2"
[Master 75014c6] Hello Test test2
3 files changed, 0 insertions (+), 0 deletions (-)
Create mode 100644 Hello
Create Mode 100644 Test
Create mode 100644 test2
[Email protected]$ git log
Commit 75014c60c33dca4873f80a80d3892cfef7b59340
Author:houenxun <[email protected]>
Date:thu Jul 9 20:41:33 2015 +0800

Hello Test test2

Commit 32A7706DF9F266522BDB223E8F4308CFCCEC01BA
Author:houenxun <[email protected]>
Date:thu Jul 9 20:08:48 2015 +0800

Commit Readme.txt
[Email protected]$

Commit again through the git commit command, see the commit record, is not found that there are two versions!

There is also a small feature where git log file can view a single file's commit record

[Email protected]$ git log readme.txt
Commit 32A7706DF9F266522BDB223E8F4308CFCCEC01BA
Author:houenxun <[email protected]>
Date:thu Jul 9 20:08:48 2015 +0800

Commit Readme.txt

Okay, here's what the local commit does, but it just does the version record, but it doesn't really show the real advantage of the version control system, and the next section continues!

This article is from the "Technical Achievement Dream" blog, please be sure to keep this source http://houenxun.blog.51cto.com/3958763/1672677

Git Combat (3)--Submit to local repository

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.