Git learning Notes (2)-Exploring Git

Source: Internet
Author: User
Tags version control system git commands

1. Create a version library

(1) Set the configuration variables for git. These settings make permanent records in a global file (. gitconfig) or System file (/etc/gitconfig)

$ git config--global user.name "Kimisme"

$ git config--global user.email [email protected]

(2) In this user's global configuration, set the GIT alias

$ git config--global alias.st status

$ git config--global alias.ci commit

$ git config--global alias.co checkout

$ git config--global alias.br branch

(3) Turn on the color display in the git command output

$ git config--global color.ui true
(4) View global configuration

$ git config--list–global

$ git config user.name

(5) Create a new working directory and create a repository

$ CD Path/to/my/workspace

$ mkdir Demo

$ CD Demo

$ git init

(6) To view the hidden directories in the workspace, the. Git directory is the Git repository (also called the Repository, repository), and the repository's directory is called the workspace

$ ls-af
(7) Create a file in the workspace

$ echo "Hello." > Welcome.txt
(8) Add the newly created file to the repository

$ git Add welcome.txt

(9) Search for the file contents of the workspace

$ git grep "He"

(10) Submit

$ git commit-m "initialized"
[Master (root-commit) 7daf0ef] Initialized
1 file changed, 1 insertion (+)
Create mode 100644 Welcome.txt

-m parameter setting submission description for "initialized"

The first line explains: This commit is submitted on the first commit (Root-commit), which is named the Master branch, and the commit ID is 7DAF0EF

The second line explains: At this point the commit modifies a file that contains a row of inserts

The third line explains: This submission creates a new file Welcome.txt

(11) Backup

$ CD.

$ git clone demo demo-step-1
Cloning into ' demo-step-1 ' ...
Done.

2. Why is there a. git directory in the root directory of the workspace?

A common feature of Git and other distributed version control systems is that the repository is located at the root of the workspace and there are no other trace files or directories in the subdirectory of the workspace;

The repository and workspace of the traditional centralized version control system are separate, even on different hosts;

Git's design of putting the repository in the root of the workspace allows all versioning operations to be done locally;

3.Git put the repository (. git directory) in the workspace directory, then some GIT commands must be executed in the workspace root directory?

When you perform an operation in a subdirectory of a Git workspace, the. Git directory is recursively looked up in the workspace directory to find the. git directory, which is the repository for the workspace. The directory where Git resides is the root directory of the workspace, and the file. Git/index records the status of the workspace file ( is actually the state of staging area)

(1) Create a directory/a/b/c in the workspace and enter the directory

$ mkdir-p a/b/c

CD a/b/c

(2) The directory where the repository. Git directory is displayed

$ git rev-parse--git-dir

(3) Show workspace root directory

$ git rev-parse--show-toplevel

(4) Relative directory relative to the root directory of the workspace

$ git rev-parse--show-prefix

(5) Displays the depth from the current directory (CD) back (up) to the root of the workspace

$ git rev-parse--show-cdup

4. The workspace and repository of the traditional centralized control system are separated, is it not safe for git to put the repository directory in the workspace?

From the storage security point of view, if you mistakenly delete the workspace, it will be deleted with the repository, the risk is indeed high;

Git cloning can reduce the risk of repository corruption due to a mix of repository and workspace

5. Who completed the submission

(1) View submission Log

$ git log--pretty=oneline
(2) Delete settings about User.Name and user.email in the GIT global configuration file

$ git config--unset--global user.name

$ git config--unset--global user.email

(3) Adding content to text

$ echo "World" >> welcome.txt
(4) Submission of text

$ git Add welcome.txt

$ git commit-m "add World"

It's a mistake!

Because User.Name and User.email are not configured

Git learning Notes (2)-Exploring Git

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.