This article brings you relevant knowledge about Git version management. The version management tool can record each modification. As long as it is submitted to the version repository, you can find the status at any previous time. ,I hope everyone has to help.
Git is a "distributed version management tool".
The version management tool can record every modification. As long as it is submitted to the version warehouse, the status at any previous time can be found.
We have all used the undo function when writing, but undo can only go back a limited number of steps. Usually, the editing software is closed and then reopened. At this time, the undo record has been cleared. The "version management tool" is different. It can record every modification. As long as it is submitted to the version warehouse, you can find the status at any previous time.
After installing the git software, create a new folder in any directory, open it, and then execute git init to create a new git warehouse (this command A hidden subdirectory named .git will be created).
Execute the command git clone remote project address to clone the warehouse on the remote server.
Git has three states, namely committed, modified, and staged.
The three states of Git correspond to the three workflows of the local warehouse. This low warehouse is composed of three trees maintained by git.
The master branch was mentioned earlier, so how to understand the branch intuitively?
Branches are used to insulate feature development. When creating a repository, master is the "default" branch. Develop on other branches and merge them into the master branch when finished.
git branch test1 | Create a branch named test1. |
---|---|
git checkout test1 | Switch the current branch to test1 |
git checkout -b test1 | Create a branch called "test1" and switch to it. |
git checkout master | Switch back to the master branch. |
git branch -d test1 | Delete the newly created branch. |
git push origin | Push the branch to the remote warehouse. |
git merge test | Merge branches. |
Use the command git pull "remote branch name" to get the code from the remote and merge it into this lower version (get (fetch) in the working directory and merge ( merge) Remote changes)
Use the command git merge "branch name" to merge other branches into the current branch.
In the first two cases, git will try to automatically merge the changes. However, conflicts may occur during merging, and you need to manually modify the files to merge these conflicts. After making changes, execute git add to mark them as merged successfully. Before merging changes, you can use git diff
If you make a mistake, you can use the command git checkout - to replace the local changes. This command will replace the files in the working directory with the latest content in HEAD (changes and new files that have been added to the staging area will not be affected)
Rename test to test1: git remote rename test test1
Remove remote warehouse test1: git remote rm test1
Cancel the temporary file: git reset filename
Undo the modification to the file: git checkout –filename
Use git log You can get the history of the local warehouse.
Use the command git log --author=bob to view only the commit records of a certain person. Add some parameters to modify the output to get the results you want.
Check which files have changed: git log --name-status
Recommended study: "Git Tutorial"
The above is the detailed content of This article will help you understand what Git version management is. For more information, please follow other related articles on the PHP Chinese website!