Git
1. Basic concepts of Git
Git is an open source distributed control system (version management tool) and is currently the most widely used version management tool.
Its purpose is to manage versions of files, since each time a project comes online, there may be some unexpected bugs, so you need to choose the last normal version to roll back. Git exists to allow developers to easily switch between versions. CodeCloud and Github are, to some extent, websites of code, functions for publishing, storing, and soliciting bugs and comments from some open source developers.
In addition to version management, Git also has great advantages in teamwork development.
In addition to the advantages above, Git has a special place - distributed management. SVN is another version management system, but it must be developed and managed on a specific network. Version control is disabled once the server goes down or the network crashes. Git's distributed management allows each developer to download all the warehouse code locally, including records of each branch, version update of the project. If the environment on the line collapses, you can simply roll back by choosing a normal history locally and then upload the code to an online location for updates.
2. How Git works
2.1 work area
When Git initializes a warehouse locally, there are three workspaces: a working directory, a staging area, a local warehouse, and a remote warehouse when associated with a remote warehouse.
- Workspace: A place where you normally store and write code;
- Stage/Index: A place to temporarily store code changes;
- Local Repository: used to store all versions of data;
3. Use of Git
3.1 Configuration of Git
Before you upload your code, first configure Git, otherwise the code repository doesn't know who you are, and you won't be able to record who uploaded and who modified the code. This configuration only needs to be configured once after Git is installed.
git config --global user.name "lyan" git config --global user.email "1055869654@qq.com"
To check if the configuration is complete, you can view it with the following commands
git config -l
If, at the end of this line of information, the user name and mailbox just configured appear, then the configuration is successful
diff.astextplain.textconv=astextplain filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true http.sslbackend=openssl http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt core.autocrlf=true core.fscache=true core.symlinks=false pull.rebase=false credential.helper=manager-core credential.https://dev.azure.com.usehttppath=true init.defaultbranch=master user.name=lyan user.email=1055869654@qq.com
3.2 Create Project
# Create a new one under the current folder. git repository git init # Create a folder named bluej under the current folder that contains. git git init bluej
3.3 Associated Remote Warehouse
git remote add origin Your warehouse address
3.4 git four steps
git add . # Submit all files in the current directory to the staging area git commit -m "feat:New Head" # Submit temporary zone files to local warehouse git pull # Pull code from remote warehouse locally for synchronization git push # Push code from local warehouse to remote warehouse git push -u origin master # If this is the first time a new warehouse has been built, add an associated branch when pushing
3.4.1 Modify commit information
If commit's comment information is mistyped, you can modify it by following the command
git commit --amend
First, by default, a vim editor opens, then type i, and the bottom left corner becomes -- INSERT -- and you can change the note information. After the modification is completed, press ESC first, exit the edit mode, and then enter: wq Enter to save.
3.5 File Status
git status
- Untracked: Files are not tracked. Untracked files are not uploaded when submitted to a local warehouse to a remote warehouse.
- Modified: The file has been edited (it has been tracked by git);
3.6 Ignore files
If you want to ignore some files and do not need git uploads, you can create a new file in the root directory. gitignore
.DS_Store # Ignore all. DS_Store Files /test # Ignore the test folder in the root directory test/ # Ignore all test folders *.html # Ignore all files suffixed with html
3.7 branch
3.7.1 View Branches
# View all local branches git branch # View all branches remotely git branch -r
3.7.2 New and Switch Branches
# New Branch git branch Branch name # Switch Branch git checkout Branch name # New and Switch Branches git checkout -b Branch name
3.7.3 Upload Branch
git push origin Branch name
3.7.4 Delete Branch
# Delete local branch git branch -d Branch name # Remove remote branch git branch -dr [remote/Branch name] # Just delete local remote branch records git push origin --delete [Branch name] # Really Delete remote branches
3.7.5 Merge Branches
# Switch to your branch first, then merge the contents of the other branches onto your branch git merge Branch name
3.8 Version fallback
To do a version rollback, you need to check the log to find the hash value of the version you want to rollback
git reset --hard Hash value
3.8.1 view log
# View a brief log git reflog # View Detailed Log git log