Git distributed version control tool
git common commands
git view configuration
View the default configuration of git
$ git config -l
View the configuration of git system
$ git config --system --list
View git user configuration information
$ git config --global --list
git configure user name and mailbox
Configure git user name
$ git config --global user.name "chenruxu"
Basic theory of git
Work area
Git has three local work areas: Working Directory, stage / index, and Repository or git directory. If you add a remote git Repository (Remote Directory) in the, it can be divided into four work areas. The conversion relationship between these four areas is as follows:
-
Workspace: workspace is where you usually store project code
-
Index / Stage: the temporary storage area is used to temporarily store your changes. In fact, it is just a file to save the information to be submitted to the file list
-
Repository: the warehouse area (or local warehouse) is a safe place to store data, which contains the data you submit to all versions. Where HEAD refers to the latest version put into the warehouse
-
Remote: remote warehouse, a server hosting code, can be simply regarded as a computer in your project team for remote data exchange
Workflow
The workflow of git is generally as follows:
1. Add and modify files in the working directory;
2. Put the files requiring version management into the temporary storage area;
3. Submit the files in the staging area to the git warehouse.
Therefore, git manages files in three states: modified, staged, and committed
git build
Build local warehouse
git init # establishes a warehouse locally
Clone remote warehouse
- #Clone a project and its entire code history (version information)
- $ git clone [url] #
- https://gitee.com/kuangstudy/openclass.git
Four states of files
Version control is the version control of a file. To modify and submit a file, you must first know the current status of the file. Otherwise, you may submit a file you don't want to submit, or the file you want to submit is not submitted.
Untracked: not tracked. This file is in the folder, but it is not added to the GIT library and does not participate in version control Through git add, the status changes to Staged
Unmodify: the file has been stored and not Modified, that is, the contents of the file snapshot in the version library are exactly the same as those in the folder There are two places for this type of file. If it is Modified, it becomes Modified If you use git rm to remove the version library, it becomes an Untracked file
Modified: the file has been modified. It is only modified without other operations This file also has two destinations. You can enter the staged state through git add. If you use git checkout, you will discard the modifications and return to the unmodified state. This git checkout takes the file from the library and overwrites the current modifications!
Staged: staging status Execute git commit to synchronize the changes to the library. At this time, the files in the library and the local files become consistent, and the files are in unmodified state Execute git reset HEAD filename to cancel the temporary storage, and the file status is Modified
Basic command operation of git
View the status of the file
#View specified file status git status [filename] #View all file status git status # git add . Add all files to staging area # git commit -m "message content" submit the content in the staging area to the local warehouse - m submit information
$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) hello.txt nothing added to commit but untracked files present (use "git add" to track)
$ git add .
Lenovo@DESKTOP-PI2EU99 MINGW64 /d/Environment/git/gitCode/localgitresp (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: hello.txt
git commit -m "new file.txt" submit the information to the local warehouse
Actual operation of git
Initialization of local library
git init
Set signature
Set user name and email address: used to distinguish the identities of different developers
Discrimination: the signature set here has nothing to do with the account and password of the code hosting center
Command:
-
Project (warehouse) level (valid only in the current library)
The location of the error message is under the config file in the current git directory
-
User level (valid for the current user logging in to the window)
Principle of proximity: when both are involved, the project level is adopted, and there is no error in either
git config #Project level without parameters git config --global #User level git config --global user.name "chenruxu" git config --global user.email "xxxxx@xxx.com"
View the global configuration information after configuration
Lenovo@DESKTOP-PI2EU99 MINGW64 ~ $ ls -lA|less Lenovo@DESKTOP-PI2EU99 MINGW64 ~ $ cat .gitconfig [core] editor = \"D:\\Front end programming software\\VScode\\Microsoft VS Code\\Code.exe\" --wait [user] name = chenruxu email = chenruxu1@163.com Lenovo@DESKTOP-PI2EU99 MINGW64 ~
Add submissions and view the status of work
git status #View file status
git add [file name] #Add files to staging area
git commmit -m "commit message"[file name] #Submit documents to local warehouse
git rm --cached <file> #File undo from staging
Realize the forward and backward of the version
View submitted log information
git log # git log --pretty=oneline #Displays a line of information git reflog #The hash value extracts a portion and displays the number of steps
Control mode in multi screen display
Space page q exit
Version control pointer
The head pointer is used to switch versions
Index value based approach
git reset --hard[Local index value] #You can switch version values # example: Lenovo@DESKTOP-PI2EU99 MINGW64 /d/Environment/git/worehouse (master) $ git reset --hard 7c05e96 HEAD is now at 7c05e96 third commit Lenovo@DESKTOP-PI2EU99 MINGW64 /d/Environment/git/worehouse (master) $ cat hello.txt 111112222 333 44
Push to remote library
git remote -v #View aliases for remote Libraries git remote add [name] [Remote address] git push [name] [Branch name master]
Errors may occur in the process of pushing remote libraries. The processing methods are:
git pull --rebase chenruxu master #Push to primary branch in remote library
In the process of pushing to a remote library, you can submit to the remote library in the form of a folder
Delete remote library
git remote rm[alias]