Git learning notes -- installation and file submission and back on Git

Posted by cooler75 on Sun, 27 Oct 2019 13:28:12 +0100

Git learning notes (1) - installation and file submission and fallback on Git

Remarks

  • &&Learning website: Liao Xuefeng's official website (easy to understand, super recommended) -- https://www.liaoxuefeng.com/wiki/896043488029600 rookie tutorial -- https://www.runoob.com/git/git-tutorial.html

  • &&Git official document (English) - https://git-scm.com/book/en/v2

  • &&Git official document (Chinese) -- https://git-scm.com/book/zh/v2

  • &&Git full command manual address - http://git-scm.com/docs

  • &&Pdf command manual – github-git-cheat-sheet.pdf

  • Git's official download website (slow) -- https://git-scm.com/downloads

  • Git for Windows domestic (image) Download Station shared on Github (fast) -- https://github.com/waylau/git-for-win

Download and install Git

stay Official download After that, install according to the default configuration options. After the installation, find "Git" - > "Git Bash" in the program, and pop up something similar to the command line window, which means that Git installation is successful!

User name and mailbox

  • Set user name and mailbox

After the installation is complete, enter the following command at the command line to set the user name and mailbox:

$git config --global user.name "Your Name"  //Set user name
$git config --global user.email "Your email"//Set up mailbox 

Because Git is a distributed version control system, every machine must report its name and Email address.

Note that the global parameter of git config command is used, which means that all Git warehouses on your machine will use this configuration. Of course, you can also specify different user names and Email addresses for a certain warehouse.

The user name and email address is a variable of the local git client, which does not change with the GIT library.

Each commit is logged with a user name and mailbox.

  • View user name and mailbox

    $ git config user.name	//User name
    $ git config user.email	//mailbox
    
  • Update user name and mailbox

    git config --global user.name "your name"
    git config --global user.email "your email"	
    

    Because there used to be a software called git (GNU Interactive Tools), GIT can only be called git core. Because Git is so famous, GNU Interactive Tools was later changed to gnuit, and git core was officially changed to GIT.

repository

Enter the following instructions to complete the creation of the version Library:

$cd e:						//Choose the path, I choose E disk
$ mkdir gitdata				//Create folder gitdata
$ cd gitdata				//Select Folder gitdata
$ mkdir learngit			//Create folder learningit
$ cd learngit				//Select Folder learningit
$ pwd						//Print current path
/e/gitdata/learngit
$ git init					//Initialize the local version library, and turn this directory into a warehouse that Git can manage:

Now an empty Git repository has been built, and there is an. Git directory in the current directory. Git is used to track and manage the version repository.

If you don't see the. git directory, it's because it's hidden by default. You can see it with the ls -ah command.

Add files to the version Library

In fact, all version control systems can only track the changes of text files (such as TXT files, web pages, all program codes, etc.), and version control system can tell the changes of text files every time. While binary files such as pictures, videos and Microsoft Word files can also be managed by version control system, they cannot track the changes of files.

If there is no historical legacy, it is strongly recommended to use standard UTF-8 encoding. All languages use the same encoding, which has no conflict and is supported by all platforms.

Recommended download Notepad++ Instead of Notepad, do not edit any text file with Windows Notepad. The reason is that when Microsoft development Notepad saves UTF-8 encoded files, 0xefbbbf (HEX) characters are added at the beginning of each file.

Create a readme.txt file (be sure to put it in the learningit directory (or subdirectory)), the contents are as follows:

Git is a version control system.
Git is free software.

Enter the following code to submit the file to Git:

$ git add readme.txt						//The first step is to choose
$ git commit -m "wrote a readme file"		//The second step is equivalent to confirmation

-After m, enter the description of this submission for future reference.

After the git commit command is executed successfully, you will be informed that 1 file changed: 1 file has been changed (our newly added readme.txt file); 2 inserts: two lines of content have been inserted (readme.txt has two lines of content).

After the first step is completed, you can submit (select multiple files) multiple times and confirm the last time.

Viewing modification records of files

  • Run the git status command to view the current status of the file's Repository:
Ah Jie@▒▒▒ܵı▒▒▒ MINGW64 /e/gitdata/learngit (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

The above command output tells us that readme.txt has been modified, but it is not ready to submit the modification.

  • To view the modification record of a text file:
Ah Jie@▒▒▒ܵı▒▒▒ MINGW64 /e/gitdata/learngit (master)
$ git diff
diff --git a/readme.txt b/readme.txt
index d8036c1..dd759bd 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,3 @@
-Git is a version control system.
+Git is a distributed version control system.
+Good.
 Git is free software.
\ No newline at end of file

  • When a new file is submitted, after entering git status:
Ah Jie@▒▒▒ܵı▒▒▒ MINGW64 /e/gitdata/learngit (master)
$ git status
On branch master
nothing to commit, working tree clean

nothing to commit currently has no changes to commit, and the working tree clean working directory is clean.

View history

Enter git log to view the modification information of all versions:

Ah Jie@▒▒▒ܵı▒▒▒ MINGW64 /e/gitdata/learngit (master)
$ git log
commit 196963208ebcdf13473f872cec73679373ea8f11 (HEAD -> master)
Author: AJie <1339126726@qq.com>
Date:   Sun Oct 27 19:18:01 2019 +0800

    wirt GPL

commit 07dab98432e07cd0cb86bb1242c9a401a4aa19e3
Author: AJie <1339126726@qq.com>
Date:   Sun Oct 27 19:11:24 2019 +0800

    add two words

commit 165e0472f58966f54b3114985fe31371bb675a13
Author: AJie <1339126726@qq.com>
Date:   Sun Oct 27 15:40:05 2019 +0800

    wrote a readme file

196963208ebcdf13473f872ec73679373ea8f11 is the commit id of the version

Enter git log --pretty=oneline to get a brief history:

Ah Jie@▒▒▒ܵı▒▒▒ MINGW64 /e/gitdata/learngit (master)
$ git log --pretty=oneline
196963208ebcdf13473f872cec73679373ea8f11 (HEAD -> master) wirt GPL
07dab98432e07cd0cb86bb1242c9a401a4aa19e3 add two words
165e0472f58966f54b3114985fe31371bb675a13 wrote a readme file

HEAD represents the version of the current file. If you want to go back to the previous version, use $git reset --hard HEAD ^; if you want to go back to the previous versions, you need $git reset --hard HEAD ^... And so on. You can also use HEAD~n where n stands for fallback several times.

You can also use the commit id before $git reset --hard +.

History of instructions

Enter git reflog to query your history instructions

Ah Jie@▒▒▒ܵı▒▒▒ MINGW64 /e/gitdata/learngit (master)
$ git reflog
07dab98 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
1969632 HEAD@{1}: commit: wirt GPL
07dab98 (HEAD -> master) HEAD@{2}: commit: add two words
165e047 HEAD@{3}: commit (initial): wrote a readme file

Summary

  • Initialize a Git repository using the git init command.

  • Add files to Git warehouse in two steps:

    1. Use the command git add. Note that you can use it repeatedly and add multiple files.
    2. Use the command git commit -m to make notes and finish.
  • To keep track of the state of your workspace, use the git status command.

  • If git status tells you that a file has been modified, you can use git diff to view the modified content.

  • The version that the HEAD points to is the current version. Therefore, Git allows us to shuttle through the history of the version, using the command Git reset -- hard commit "ID.

  • Before shuttling, you can use git log to view the submission history, so as to determine which version you want to backoff to.
    git commit -m ', make notes and finish.

  • To keep track of the state of your workspace, use the git status command.

  • If git status tells you that a file has been modified, you can use git diff to view the modified content.

  • The version that the HEAD points to is the current version. Therefore, Git allows us to shuttle through the history of the version, using the command Git reset -- hard commit "ID.

  • Before shuttling, you can use git log to view the submission history, so as to determine which version you want to backoff to.

  • To go back to the future, check the command history with git reflog to determine which version you want to go back to.

Topics: git github Windows encoding