catalogue
Modification of configuration file
Differences with svn
svn: centralized version control system
The version library is unique: it is located on the server and needs to be developed online
git: distributed version control system
The version library is not unique: you can have a complete code library locally without networking
git easy tutorial
Local end: https://npm.taobao.org/mirrors/git-for-windows/ Download and install the latest version
It is recommended to use vim as the default editor
Far end: https://gitee.com/
New warehouse
P.S. items are created in warehouse units. One item corresponds to one warehouse
Right click in the project directory to open git bash here
gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode/git_test (master) $ git init Initialized empty Git repository in D:/gitcode/git_test/.git/
configuration file
Add a signature to distinguish developers
gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode $ git config --global user.name gl gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode $ git config --global user.email 1556481332@qq.com gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode $ git config --global --list user.name=gl user.email=1556481332@qq.com
Code management
Status view
git status view warehouse information
$ git status On branch master #Branch information No commits yet #Local library nothing to commit (create/copy files and use "git add" to track) #Staging area
Code submission
New file git_test.txt, the file is not tracked
git add saves the file to the temporary storage area, and git rm restores the untracked state
$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) git_test.txt #The file is not tracked and needs to be add ed to the staging area nothing added to commit but untracked files present (use "git add" to track) $ git add git_test.txt warning: LF will be replaced by CRLF in git_test.txt. The file will have its original line endings in your working directory $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: git_test.txt #The file is not submitted and needs to be commit ted to the local warehouse
git commit submits the code to the local warehouse. You can use - m "log information" to record the log information
$ 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: git_test.txt #Show modified files no changes added to commit (use "git add" and/or "git commit -a") #If it is not created for the first time, you can skip the staging area and directly commit to the local warehouse $ git commit -m "the second commit" git_test.txt [master a1af50c] the second commit #journal 1 file changed, 1 insertion(+), 1 deletion(-) #Modify the information, insert a line and reduce one line
Version selection
git log view historical version
$ git log commit a1af50ccfaa5bb90c2ccc8230f0e0599ae4c7e3e (HEAD -> master) #head points to the current version Author: gl <1556481332@qq.com> Date: Sat Aug 7 11:14:54 2021 +0800 the third commit commit c525169ce4fb45a7dfc2e9437b879b3f7f0fd3eb Author: gl <1556481332@qq.com> Date: Sat Aug 7 11:08:27 2021 +0800 the second commit commit 3eb0ae3e07a71924c33a3bde234778b56e2160b0 Author: gl <1556481332@qq.com> Date: Sat Aug 7 10:56:33 2021 +0800 New project established $ git log --pretty=oneline #Single line display version log a1af50ccfaa5bb90c2ccc8230f0e0599ae4c7e3e (HEAD -> master) the third commit c525169ce4fb45a7dfc2e9437b879b3f7f0fd3eb the second commit 3eb0ae3e07a71924c33a3bde234778b56e2160b0 New project established $ git log --oneline #Show partial hash values a1af50c (HEAD -> master) the third commit c525169 the second commit 3eb0ae3 New project established $ git reflog #Show all historical versions a1af50c (HEAD -> master) HEAD@{0}: commit: the third commit c525169 HEAD@{1}: commit: the second commit 3eb0ae3 HEAD@{2}: commit (initial): New project established
git reset --hard hash value} complete version selection
$ git reset --hard a1af50c HEAD is now at a1af50c the third commit
supplement
git reset --soft: only move the local library head pointer
git reset --mixed: move the local library head pointer and recover the staging area
git reset --hard: local library + staging area + work area (common)
File deletion and recovery
The deleted version of the file also needs to be submitted to the local library through add and commit
To restore, use git reset to select the version before deletion
File comparison
Compare with any version in the local library
$ git diff Hash value git_test.txt
Branch Management
effect
- Synchronous development of multiple functions
- The failure of a branch will not affect the main line and other branches
basic operation
- Create branch git branch branch branch name
- View branch git branch -v
- Switch branch git checkout branch name (complete with tab)
- Merge branch
- Switch to mainline (when branches merge to mainline)
- git merge branch name
- conflict resolution
At the same time, the original branches are modified, and the merged branches will conflict
<<<<<<< HEAD conflict master #This branch ======= conflict branch1 #Other branches to be merged >>>>>>> branch1
Resolve the conflict. After removing the prompt, use git add and git commit to merge. The file name cannot be added to commit here
appendix
Modification of configuration file
Add
gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode/git_test (master) $ git config --global --list gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode/git_test (master) $ git config --global user.name gl gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode/git_test (master) $ git config --global --list user.name=gl
delete
gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode/git_test (master) $ git config --global --list user.name=gl gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode/git_test (master) $ git config --global --unset user.name gl@DESKTOP-9ITKPJH MINGW64 /d/gitcode/git_test (master) $ git config --global --list
system level: - system - actual Directory: Git/etc/gitconfig
User level -- global actual Directory: c:/user / user name / gitconfig
Project level --loacl# actual Directory: project / git/config
Priority: Project > User > system
vim common commands
set nu displays the line number