Table of contents
Basic Linux Commands
Because Git uses Linux commands, a brief summary of the basic Linux (usually you must use these basic commands):
1. cd: change directory
2. cd..: Go back to the previous directory and directly cd to the default directory
3, pwd: display the current directory path
4. ls(||): All files in the current directory are listed, but the contents of the two || lists are more detailed
5. touch: Create a new file, such as touch index.js will create a new index.js file in the current directory
6, rm: delete a file, rm index.js will delete the index.js file
7. mkdir: Create a new directory, that is, create a new file
8. rm -r: delete a folder, rm -r src delete the src directory
Note : rm -rf / deletes all files in the computer, do not try it in Linux! Otherwise: If you run away, I will see the punishment
9, mv: move files, mv target file target folder, so write to ensure that the file directory is in the same folder
10. reset: reinitialize the terminal / clear the screen
11, clear: clear screen
12, history: view command history
13. help: help
14. exit: exit
15. #: indicates a comment
16. vim: a powerful text editor with 3 modes: command mode, edit mode, bottom line command mode.
Git common commands
command name | effect |
---|---|
git config --global user.name username | Set user signature |
git config --global user.email mailbox | Set user password |
it's hot | Initialize native library |
git status | View local library status |
git add filename | add to staging area |
git commit -m "log info" filename | commit to local repository |
git reflog | View history |
git reset --hard version number | version shuttle |
Set user signature password
Note here: The user signature must be set for the first installation of Git , otherwise the code cannot be submitted. The function of the signature is to distinguish the identities of different operators. The user's signature information can be seen in the submission information of each version to confirm who made the submission. (Signature email information can be filled in casually, git will not recognize whether it exists, of course, you can sign with real-name email during the company's development process) Note : Setting the user's signature here has nothing to do with the account that will log in to GitHub (or its code hosting center) in the future .
Here are some additional knowledge points :
Text editor : Set the default text editor used by Git, usually Vi or Vim. If you have other preferences, such as Emacs, you can reset them:
$ git config --global core.editor emacs
Diff Analysis Tool : Which diff analysis tool to use when resolving merge conflicts. For example, if you want to use vimdiff instead, you can execute:
$ git config --global merge.tool vimdiff
Git understands the output of merge tools such as kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff. Of course, you can also specify the use of tools developed by yourself.
View configuration information : To check the existing configuration information, you can use the git config --list command: (Sometimes you see repeated variable names, which means they come from different configuration files (such as /etc/gitconfig and ~/ .gitconfig), but in the end Git actually uses the last one.)
$ git config --list
http.postbuffer=2Muser.name=runoob
[email protected]
Initialize native library
In the daily development process, when we want to initialize the local library, we can enter the file directory to be initialized in advance, right-click Git Bash to enter, and enter git init to initialize the local library. The generated .git file is not recommended for manual modification, otherwise it may fail to run.
If the .git file does not appear on the current page, it may be that the default file set by your computer is hidden, and you can correct it.
The command to view files in linux is ll, but the command to view hidden files is ll -a.
View local library status
On branch master: Prompt that the current local library is in the master branch
No commits yet: Nothing has been submitted yet, indicating that it is an empty address library
nothing to commit: nothing to commit
nothing to commit:
Use vim to create say.txt file, press Enter to enter file editing mode
Press i to enter insert (insert/edit) mode, press Esc to exit insert mode; to paste and copy, you need to exit Esc mode first, then yy is copy, p is paste (paste the content of the previous line to the next line). To save the file and exit, you need to exit the editing mode and then enter: ":wq" three English characters, press Enter.
You can then view the existence of the file and the contents of the file.
Next, check the status of the local library. Although the file exists, only the workspace exists, and the prompt asks us to add the file to the staging area.
add to staging area
warning: LF will be replaced by CRLF in say.txt.
Git's newline checking feature. LF is newline under linux, and CRLF is enter + newline; Git can automatically convert line endings CRLF to LF when you commit, and LF to CRLF when you check out code.
Add hello.txt and say.txt to the temporary storage area, you can see the following status, the picture also reminds us how to delete the files in the temporary storage area, when we delete the files in the temporary storage area, the files are not actually deleted, It also remains in our native library.
commit to local repository
Submit the files in the staging area to the local library to form your own historical version.
Checking our local repository status now shows that our say.txt file has been committed.
View history
Of course, if you want to modify the previous say.txt file, you only need to edit vim, upload it to the staging area after editing, and submit it to the local library.
version shuttle
Git switches versions, and the bottom layer is actually moving the HEAD pointer. The process is as follows:
The shortcut keys for copy and paste here are: Ctrl + Insert and Shift + Insert, just copy the version number to be shuttled.
You can look at the directory file. The content of the file is the current version number, indicating that the branch pointed to by the pointer is master and the master pointed to the current version.
Summarize
The workflow of Git is generally like this:
1. Add and modify files in the working directory; (userMapper.xml)
2. Put the files that need version management into the staging area; (git add)
3. Submit the files in the staging area to the git repository (git commit)
Therefore: files managed by git have three states: modified, staged, committed
Here is a summary of the Git workspace, staging area and repository concepts:
Workspace: This is the directory you can see on your computer.
Temporary storage area: English is called stage, or index. It is generally stored in the index file (.git/index) under the ".git directory", so we sometimes call the temporary storage area an index.
Repository: The workspace has a hidden directory .git, which is not a workspace, but a Git repository.