GIT#
Partition#
- Workspace
The directory visible on the computer.
- Staging Area
After git add
, the modified files in the workspace will be added to the staging area.
- Repository
After git commit
, the files in the staging area will be packaged as a commit and placed in the repository.
Git Partition Legend#
#
Basic Operations#
File Operations#
- git add
xxxxxx.java
/folder
- git commit
-m
-v
- git stash
pop
- git reset
head
--hard
git stash/pop#
Used to temporarily save and restore modifications, can be used across branches
Note: Stash can only be executed before add! (i.e., before adding to the staging area)
commit message specification#
- feat(module): New feature.
- fix: Fix bugs, can be bugs discovered by QA or bugs discovered by developers themselves.
- docs: Documentation.
- style: Formatting (changes that do not affect the code execution).
- refactor: Refactoring (code changes that are neither new features nor bug fixes).
- perf: Optimization, such as performance improvement and experience enhancement.
- test: Add tests.
- chore: Changes to the build process or auxiliary tools.
- revert: Roll back to the previous version.
- merge: Code merging (conflict resolution, etc.).
commit message specification#
Basic Operations#
Branch Operations#
- git checkout
-b
branch
- git merge
branch
- git rebase
branch
- git pull
remote
branch
- git push
remote
branch
Merge Conflict#
<<<<<<< HEAD:index.html
<div id="footer">contact : [email protected]</div>
=======
<div id="footer">
please contact us at [email protected]
</div>
>>>>>>> iss53:index.html
git merge --abort
#
Characteristics of Merge#
Advantages#
- Easy to use
- Retains a record of each step
- Retains the original record of the source branch
Disadvantages#
- Retains a record of each step
Rebase#
Like merge, the main function is to merge branches, but there are many different details.
Move all modifications made to a branch to another branch, as if "replaying" them.
Rebase#
Execute git rebase master
on the experiment
branch to rebase the modifications in C4
onto C3
.
Differences between Rebase and Merge#
1. Difficulty of use
Merge is easier to understand than rebase.
2. Different results in recording git operation history
Merge records all merge operations, while rebase only retains a serial commit record.
History after Merge#
Too Many Merge Records#
History after Rebase#
Branch Collaboration#
Git Work Flow#
Git Work Flow#
Categories#
- Git Flow
- GitHub Flow
- GitLab Flow
Git Flow#
A collaboration model based on Git branch capabilities.
Branch Types#
- Master Latest release version
- Dev Latest development progress
- Release Pre-release branch
- HotFix Branch for emergency bug fixes
- Feature Module development branch
General Process#
- Create the
dev
branch frommaster
. - Create various feature branches from
dev
and develop on the feature branches. - The completed features will be merged into
dev
. - After completing a stage of feature development, create a
release
branch for testing and other pre-release activities. - Problems discovered during the release period will be fixed in the
release
branch and the fixes will be merged intodev
. - After passing the release test, merge into
master
andtag
a version record inmaster
. - If a bug occurs online, create a
hotfix
branch frommaster
to fix the issue and merge it intomaster
anddev
. [Special]
#
Github Flow#
Based on Git Flow, adds fork
and Pull Request