Before use
- Install Git
- Configure name and email
git config--"Your Name" git config--"[email protected]"
Working with local single-user workflows
- Initial git management repository
Git init
- Add files to a git repository
git add readme.txt
- Submit files to a git repository
"Upload Readme File"
Remote single-user workflow
- Clone a remote Git repository or associate a local repository
https://github.com/cizel/soft_backup
Git remote add origin git@github. Com:cizel/soft_backup.git
- Add files to a git repository
git add readme.txt
- Submit files to a git repository
"Upload Readme File"
- Upload to a remote git repository
Push Origin Master
Multi-User Branch usage policy
Basic syntax
To view branches:git branch
To create a branch:git branch <name>
To switch branches:git checkout <name>
Create + switch Branches:git checkout -b <name>
Merge a branch to the current branch:git merge <name>
To delete a branch:git branch -d <name>
Use of Branches
GIT creates a develop branch command:
git checkout-b Develop Master
Commands to publish a develop branch to the master branch
# Switch to Master branch git checkout Master # Develop branch to merge git merge--no-ff Develop
tip:
--no-ff
--no-ff
policies that use quick Merge are not used
Use
--no-ff
A normal merge is performed and a new node is generated on the master branch. In order to ensure a clear version evolution, we would like to adopt this approach.
- Management policies for branches
First, the main branch master
First, the code base should have one, and only one main branch. All the official versions available to the user are published on this main branch.
Second, the development branch develop
The main branch is used only to distribute major versions, and daily development should be done on another branch. The branch we use for development is called develop.
Third, functional branches
The first is the functional branch, which is designed to develop a particular function that is separated from the develop branch. After the development is completed, it is to be merged into develop.
Iv. Pre-Release branch
The pre-release branch is separated from the develop branch and must be merged into the develop and master branches after the pre-release is finished. Its name can be used in the form of release-*.
Patch Bug Branch patch Bug branch is divided from the master branch. After patching is complete, merge into master and develop branches. Its name can be used in the form of fixbug-*.
Encounter problems See and compare
# tells you that a file has been modified git status#可以查看修改内容git diff
Version forward and backward
Log# View the command history to determine which version of Git to go back to in the future Reflog
Modify version
git reset--hard commit_id
Undo Commit
Reset--hard commit_idpush Origin HEAD--force
The difference between git revert and git reset
- Git revert is a new commit to roll back before Commit,git reset is to delete the specified commit directly.
- In the rollback of this operation, the effect is similar. However, there is a difference when you continue to merge old versions of the previous version later. Because git revert is a reverse commit "medium and" before the commit, so later merging old branch, cause this part of the change will not reappear, but git reset is to remove some commits on a certain branch, As a result, when the old branch is re-merge, these rollback commits should also be introduced.
- Git reset is to move head backwards, and git revert is head to move forward, but the new commit content and the content to revert is just the opposite, can offset the content to be revert.
The difference between git fetch and git pull
- git fetch: The equivalent of getting the latest version from remote to local, not automatically merge
- Git pull: the equivalent of getting the latest version from the remote and merge to the local, git fetch is equivalent to git fetching + git merge
git using diagrams