Git basis
Git configuration before use
Configuring user name and email (useful when many people work together)
Configuration Name
$ git config --global user.name xxxx
Configure Mailbox
$ git config --global user.email [email protected]
Check whether the configuration is successful
$ git config --list
Note :
Change Configuration -> Repeat the command
Or directly modify the
C:\Users\用户\.gitconfig
path is not uniform
Step submission
git init
Initialize git repositorygit status
Viewing File Statusgit add
File List trace filegit commit -m 提交信息
Submit code to the repositorygit log
View submit records
git log --pretty=oneline
to see simple commit record
Undoing Changes
Overwrite files in the working directory with the files in the staging area:
git checkout
The documents in the work area to make changes complete withdrawal
git checkout -- 文件名
Undo divided into two cases:
After 1.readme.txt automatically modified, not into the staging area, use the back and undo changes to the repository exactly the same state.
2. Another is to put readme.txt already staging area, and then they made the changes, undo changes returned to the state after adding the staging area.
The file is deleted from the staging area:
git rm --cached 文件名
The recovery git repository specified in the updating record came out, and covers the staging area and working directory:
git reset --hard commitID
Git commit modify information in the author
Use --amend modify author:
git commit --amend --author=‘xxx <[email protected]>’
Input
git rebase --continue
end modification
Back to the previous version
`` git reset --hard HEAD^ `` 回溯到上一个版本
`` git reset --hard HEAD^^ `` 回溯到上上个版本
`` git reset --hard HEAD~100 `` 回溯到100个版本之前
View the file contents
cat 文件名称
Advanced Git
Branch
A copy, to avoid affecting the development of the main line
Branch subdivision
- Main branch (master): first submitted a branch generated automatically update records to the git repository.
- Development branch (develop): developed as a branch, created based on the master branch.
- Feature branches (feature): Create a branch-based development as a function of the development of specific branches.
Branch command
git branch
View branchgit branch 分支名称
Creating a branchgit checkout 分支名称
Switching branchgit checkout -b 分支名称
Create and switch to the branch (i.e. first two combined)git merge 来源分支
Merge branchgit branch -d 分支名称
Deletion branch (branch can not be operated in a state) (- D forced to remove uppercase)
note:
After the development branch file you want to commit and then switch the main branch, branch or file will appear in the main branch inside.
Temporarily save changes
git can not commit the changes, just extract all the changes on the branch and store that allows developers to get a clean copy of the temporary turn to other work. Copy to "clipboard", you can "stick" to other branches.
Scenes:
- Store temporary changes:
git stash
- Restore temporary changes:
git stash pop
Github
Registration Github account
Multiplayer collaborative development process
- A local repository is created in your computer
- A creates a remote repository in GitHub
- A local repository will be pushed to the remote repository
git push
- B clone a remote repository to local development
git clone
- B local warehouse development to push content to a remote repository
git push
- A remote repository latest local content got me
git pull
Creating a warehouse
Pushed to the remote repository
git push **远程仓库地址** 分支名称
git push 远程仓库地址别名 分支名称
git push -u 远程仓库地址别名 分支名称
-u
Remember PUSH address and branch, next only need to entergit push
git remote add 远程仓库地址别名 远程仓库地址
The first submission requires a user name and password, the computer will remember the password in the Credential Manager, and the second would not have had.
Pull warehouse
- Clone remote repository to local:
git pull 仓库地址
Cloning warehouse
- Clone remote repository to local:
git clone 仓库地址
Pull remote repository latest version
- The latest version pulled a remote repository to local:
git pull 远程仓库地址 分支名称
Resolve conflicts
When people develop the same project, if two people modify the same file in the same place
git pull
- Manually resolve conflicts
git push
Cross-team collaboration (github)
fork
To their remote repositoryclone
To locally modifypush
To a remote repositorypull request
Sent to the original author- View the original author
commit
audit - Author
merge pull request
SSH login avoid dense (recommended) (to be improved)
Generate the key:
ssh-keygen
Key store directory:
C:\User\用户\\.ssh
Public Key Name:
id_rsa.pub
Private Key Name:
id_rsa
Add the keys Github
Copy the SSH Address:
Setting up ssh alias:
$ git remote add origin_ssh SSH地址
Remote Push:
$ git push origin_ssh master
Git ignore list
- Will not need to file name added to this file, it will ignore these files when executing commands git
touch .gitignore
Rule action
/mtk 过滤整个文件夹
*.zip 过滤所有.zip文件
/mtk/xiaojian.py 过滤某个具体文件
!xiaojian.py 不过滤某个具体文件
Note : Before you push a certain file if you create .gitignore file, even if you write in .gitignore file filtering rules of the file, the rule will not work, git will still perform the file version management.
Configuration syntax
以斜杠“/”开头表示目录;
以星号“*”通配多个字符;
以问号“?”通配单个字符
以方括号“[]”包含单个字符的匹配列表;
以叹号“!”表示不忽略(跟踪)匹配到的文件或目录。
Note : git for .gitignore profile by rows from the top down rule matching
To add a description warehouse
Add in the warehouse root directory readme.md
file to
Common graphical management tools (GUI)
Github for Desktop: Github official produced
Sourse tree: the old GUI
TortoiseGit: namely turtles git