Git
- Git is a source code management tools (version control tools)
Distributed version management tools, centralized
- git belong distributed
- svn centralized
git installation
initialization
warehouse
- In fact, it creates a hidden directory .git
- Command:
git init
;- .Git directory in which you want to create the directory, which directory is open Tools and then write command.
- Usually execute this command in the root directory of the project.
User Info
- Configuring Username:
git config user.name "testName"
- Configuration E-mail:
git config user.email "[email protected]"
- View configuration information:
git config --list
Submit code
1. The first code to the staging area
- command:
git add 文件路径
- Example:
git add ./reademe.md
- You can use
git add .
this command batch to add all modified files in the current directory to the staging area.
- command:
2. The document submitted to the staging area of the warehouse
- command:
git commit -m "注释"
- Example:
git commit -m "我们添加了一个新的功能"
- -m represents a specified string, as described filed (corresponding note);
- command:
The combined add and commit commands
git commit -a -m "这是使用合并添加与提交的操作"
;- Here -a parameter indicates the file after adding together all modifications to the staging area. (Only valid for modified files, add new files to no effect)
- Configuring Username:
View the work area status
- command:
git status
- Some documents are not required to submit in the project, we need to ignore it
- .Git folder need to create a new directory called .gitignore file
and then write in this file to specify the path of the file on need.
Example: /css/a.css: /css/*.css : /a.html
Compare file difference
- command:
git diff
- Staging area used to compare file content with the workspace file content difference
- If there is no staging area file, it will work with the code and recently submitted a contrast
- Command:
git diff --cached
the difference between files and files in the staging area of the warehouse compare - A comparison of the difference of the two documents previously submitted
- command:
git diff [版本号1] [版本号2] [想比较的文件路径]
- command:
View Log
- Command:
git log
You can view a log of every submission - Command:
git log --oneline
represents the commit log output using a simple form
Version rollback
- command:
git reset --hard Head~0
- Fall back time of the last submission, ~ 0 can be omitted
- command:
git reset --hard Head~1
- This is the code that will fall back to a state of submission on
command:
git reset --hard Head~2
- Last fall back on
command:
git reset --hard 版本号
- Generated by each commit to roll back the version number version
By
git reflog
operating record before switching command can view all versions, you can retreat to the specified version by version number of this command to get back.
Creating a branch
- command:
git branch [分支名]
- Create a new branch
- command:
git branch
- See all current branch
Switching branch
- command:
git checkout [分支名]
- Normal operation can be performed after the branch after the branch switching handover
Merge branch
- command:
git merge [分支名]
- The specified git branch into the current branch.
Deleted branches
- command:
git branch -d [分支名]
- Delete the specified branch, -d parameter represents the delete operation to be performed
git submission of conflict
- If you can not automatically merge git branch, there will be conflict, we need to manually resolve the conflict, and then submit again
github
git and github
- git version management tool
- github is a website, but the site offers git server functionality
Git upload code to the server (push)
command:
git push [远程服务器地址] [远程服务器的分支]
- Example:
git push https://github.com/huoqishi/test002.git master
- Example:
Some commands can be used to simplify uploading
- The remote server address written in the form of a variable
git remote add [变量名] [远程服务器地址]
- Example:
git remote add origin https://github.com/huoqishi/test002.git
- So then you can directly use the address of origin instead of writing a git push back
git push origin master
- The remote server address written in the form of a variable
- Also you can make further simplified
- Plus -u parameters in the push, it will default to establish a local branch currently associated with the specified remote branches, you do not need to enter the name of the branch the next time the Push
git push origin
;
- Plus -u parameters in the push, it will default to establish a local branch currently associated with the specified remote branches, you do not need to enter the name of the branch the next time the Push
###
Original: Big Box knowledge git summary