Git – flow is introduced
- preface
Git is the branch of the most powerful functions, but how to branch can more effectively improve the development efficiency, reduce because of merging code problems, needs a branch model to specification, before there is in the git flow has been branching process model theory, it was based on this theory, the manual operation branch in accordance with the specification, Git Flow simplifies operations by simplifying part of the flow to commands, without adding new functionality.
- The installation
The avH version of Git-flow is currently popularCopy the code
npm install -g git-flow-avhCopy the code
- Initialize the project
# cd /pass/to/your/projectCopy the code
Git init is not required to execute git initCopy the code
git flow initCopy the code
- Branch model
After initializing the project directory with Git flow, you can only see two branches (long branches) :
Master branch: A branch used to go live, a protective branch that contains only stable code that has been tested. Developers cannot work on this branch or commit changes directly to the Master branch.
Develop branch: the basic branch that developers use for any new development. When starting a new feature branch, separate it from Develop; In addition, this branch also brings together all completed functions, waiting to be merged into the Master branch.
The first two branches are called long-term branches and exist throughout the life of the project, while the other branches are temporary, created as needed, and removed when their tasks are completed.
Feature branch: The branch most frequently used in normal development work.
Create a functional branch:
The following command creates a feature branch named “feature/<branch-name>”, which is checked out from Develop by default. Checking out a separate branch is an important rule in version control.
# git-flow create feature branchCopy the code
$ git flow feature start <branch-name>Copy the code
Complete functional branches:
# git-flow create feature branchCopy the code
$ git flow feature finish <branch-name>Copy the code
Copy the code
This will consolidate the code in the current branch into the ‘develop’ branch, after which git-flow will clean up the branch, removing the currently completed functional branch and switching the branch to ‘develop’.
The release branch:
Create the release branch:
$git flow release start 1.1.5Copy the code
When you consider the current ‘Develop’ branch code to be a mature release, that means: first, it includes all new features and necessary fixes; Second, it has been thoroughly tested. If both of these are true, it’s time to create the Release branch.
Note: The release branch is named using a version number. This naming scheme will allow Git-flow to automatically flag the release commit as appropriate after we have completed the release.
Complete the Release branch:
$git flow release Finish 1.1.5Copy the code
The preceding commands perform the following operations:
- Git-flow pulls the remote repository to make sure it is currently up to date.
- Release content is merged into the master and Develop long-term branches. Not only will the production code be up to date, but new branches of functionality will be based on the latest code.
- For easy identification and historical reference, the release teaser is labeled with the name of the release
- To clean up, the version branch is removed and returned to the Develop branch.
Note: From Git’s point of view, the release is now complete, and depending on the Settings, the commit to the master may have triggered the compile deployment process. Or manually deploy.
Hotfix branches:
Many times when a release is fully tested, minor bugs may be found, in which case Git-Flow provides a specific hotfix workflow.
Create hotfix branch:
$ git flow hotfix start bug-fixedCopy the code
The above command creates a branch named hotfix/bug-fixed, which is a fix to the production code, so the hotfix branch is checked out based on the Master branch.
This is the most obvious difference from the Release branch, which is checked out based on the Develop branch. Because you can’t fix production code on a branch that’s not completely stable.
As with release, fixing this error directly affects the version number of the project.
Complete the Hotfix branch:
$ git flow hotfix finish bug-fixedCopy the code
The command above is similar to releasing a release:
- The completed changes are merged into the Master, as well as into the Develop branch, to ensure that the error does not reappear in the next release;
- The hotfix will be marked for easy reference;
- The current Hotfix branch will be removed and switched to the Develop branch;
Note: After completing the Hotfix branch, start the build deployment process either automatically or manually
- conclusion
Main branches
- Master: Always in production-ready state
- Develop: The latest development status
Auxiliary branch
- Feature: Branch to develop new features based on Develop, merge back to Develop after completion
- Release: a branch that prepares a version for release, used to fix bugs. Merge back to Develop and Master based on develop
- Hotfix: Fixes issues on the master that must be released immediately before the release. Master based, merge back to Master and Develop after completion
Git command list
Git Workflow Flowchart
- Initialize the warehouse
Create a new Git repository in the current directoryCopy the code
$ git initCopy the code
Copy the code
Create a new directory and initialize it as a Git code baseCopy the code
$ git init [project-name]Copy the code
Copy the code
Download a project and its entire code historyCopy the code
$ git clone [url]Copy the code
- Configure Git
Git’s Settings file is.gitconfig, which can be in the user home directory (global configuration) or in the project directory (project configuration).
Display current Git configurationCopy the code
$ git config --listCopy the code
Copy the code
Edit Git configuration filesCopy the code
$ git config -e [--global]Copy the code
Copy the code
Set user information when submitting codeCopy the code
$ git config [--global] user.name "[name]"Copy the code
$ git config [--global] user.email "[email address]"Copy the code
Copy the code
- Add delete file
Add the specified file to the staging areaCopy the code
$ git add [file1] [file2] ...Copy the code
Copy the code
Add the specified directory to the staging area, including subdirectoriesCopy the code
$ git add [dir]Copy the code
Copy the code
Add all files from the current directory to the staging areaCopy the code
$ git add .Copy the code
Copy the code
Before adding each change, ask for confirmationCopy the code
For multiple changes to the same file, we can implement multiple commitsCopy the code
$ git add -pCopy the code
Copy the code
Delete the workspace file and place the deletion in the staging areaCopy the code
$ git rm [file1] [file2] ...Copy the code
Copy the code
# stop tracking the specified file, but it will remain in the workspaceCopy the code
$ git rm --cached [file]Copy the code
Copy the code
Rename the file and place the rename in the staging areaCopy the code
$ git mv [file-original] [file-renamed]Copy the code
Copy the code
- Submit code
Submit the staging area to the warehouse areaCopy the code
$ git commit -m [message]Copy the code
Copy the code
Submit the file designated for the staging area to the warehouse areaCopy the code
$ git commit [file1] [file2] ... -m [message]Copy the code
Copy the code
Commit workspace changes since the last commit, directly to the warehouseCopy the code
$ git commit -aCopy the code
Copy the code
Display all diff information when submittingCopy the code
$ git commit -vCopy the code
Copy the code
Use a new COMMIT instead of the previous commitCopy the code
If there are no new changes to the code, it is used to overwrite the commit information from the last commitCopy the code
$ git commit --amend -m [message]Copy the code
Copy the code
Rework the last commit and include new changes to the specified fileCopy the code
$ git commit --amend [file1] [file2] ...Copy the code
Copy the code
- Branch command
# list all local branchesCopy the code
$ git branchCopy the code
Copy the code
List all remote branchesCopy the code
$ git branch -rCopy the code
Copy the code
List all local and remote branchesCopy the code
$ git branch -aCopy the code
Copy the code
Create a new branch, but remain in the current branchCopy the code
$ git branch [branch-name]Copy the code
Copy the code
Create a new branch and switch to that branchCopy the code
$ git checkout -b [branch]Copy the code
Copy the code
Create a new branch that points to commitCopy the code
$ git branch [branch] [commit]Copy the code
Copy the code
Create a new branch and set up a trace relationship with the specified remote branchCopy the code
$ git branch --track [branch] [remote-branch]Copy the code
Copy the code
Switch to the specified branch and update the workspaceCopy the code
$ git checkout [branch-name]Copy the code
Copy the code
# Switch to the previous branchCopy the code
$ git checkout -Copy the code
Copy the code
Establish a trace between an existing branch and a specified remote branchCopy the code
$ git branch --set-upstream [branch] [remote-branch]Copy the code
Copy the code
Merge the specified branch into the current branchCopy the code
$ git merge [branch]Copy the code
Copy the code
Select a COMMIT and merge it into the current branchCopy the code
$ git cherry-pick [commit]Copy the code
Copy the code
# delete branchCopy the code
$ git branch -d [branch-name]Copy the code
Copy the code
# delete remote branchCopy the code
$ git push origin --delete [branch-name]Copy the code
$ git branch -dr [remote/branch]Copy the code
Copy the code
- Tag command
# list all tagsCopy the code
$ git tagCopy the code
Copy the code
Create a new tag for the current commitCopy the code
$ git tag [tag]Copy the code
Copy the code
# Create a new tag before specifying commitCopy the code
$ git tag [tag] [commit]Copy the code
Copy the code
# delete the local tagCopy the code
$ git tag -d [tag]Copy the code
Copy the code
# delete remote tagCopy the code
$ git push origin :refs/tags/[tagName]Copy the code
Copy the code
# check the tag informationCopy the code
$ git show [tag]Copy the code
Copy the code
# submit the specified tagCopy the code
$ git push [remote] [tag]Copy the code
Copy the code
# submit all tagsCopy the code
$ git push [remote] --tagsCopy the code
Copy the code
Create a new branch that points to a tagCopy the code
$ git checkout -b [branch] [tag]Copy the code
Copy the code
- Check the information
# show the changed fileCopy the code
$ git statusCopy the code
Copy the code
Display the version history of the current branchCopy the code
$ git logCopy the code
Copy the code
Display the commit history and the files that changed each commitCopy the code
$ git log --statCopy the code
Copy the code
# Search submission history by keywordCopy the code
$ git log -S [keyword]Copy the code
Copy the code
Display all changes after a commit, with each commit occupying one rowCopy the code
$ git log [tag] HEAD --pretty=format:%sCopy the code
Copy the code
All changes made after a commit must match the search criteriaCopy the code
$ git log [tag] HEAD --grep featureCopy the code
Copy the code
Display the version history of a file, including file renamingCopy the code
$ git log --follow [file]Copy the code
$ git whatchanged [file]Copy the code
Copy the code
# display every diff associated with the specified fileCopy the code
$ git log -p [file]Copy the code
Copy the code
# show the last 5 commitsCopy the code
$ git log -5 --pretty --onelineCopy the code
Copy the code
# display all submitted users, sorted by number of submitted usersCopy the code
$ git shortlog -snCopy the code
Copy the code
# show when and by whom the specified file was modifiedCopy the code
$ git blame [file]Copy the code
Copy the code
Display the difference between the staging area and the workspaceCopy the code
$ git diffCopy the code
Copy the code
Show the difference between the staging area and the last commitCopy the code
$ git diff --cached [file]Copy the code
Copy the code
Show the difference between the workspace and the latest COMMIT of the current branchCopy the code
$ git diff HEADCopy the code
Copy the code
Display the difference between two commitsCopy the code
$ git diff [first-branch]... [second-branch]Copy the code
Copy the code
# show how many lines of code you wrote todayCopy the code
$ git diff --shortstat "@{0 day ago}"Copy the code
Copy the code
Display metadata and content changes for a commitCopy the code
$ git show [commit]Copy the code
Copy the code
Display the files that have changed during a commitCopy the code
$ git show --name-only [commit]Copy the code
Copy the code
Display the contents of a file at the time of a commitCopy the code
$ git show [commit]:[filename]Copy the code
Copy the code
Displays the most recent commits for the current branchCopy the code
$ git reflogCopy the code
Copy the code
- Remote synchronization
Download all changes to the remote repositoryCopy the code
$ git fetch [remote]Copy the code
Copy the code
Display all remote repositoriesCopy the code
$ git remote -vCopy the code
Copy the code
Display information about a remote repositoryCopy the code
$ git remote show [remote]Copy the code
Copy the code
Add a new remote repository and name itCopy the code
$ git remote add [shortname] [url]Copy the code
Copy the code
Fetch the changes from the remote repository and merge them with the local branchCopy the code
$ git pull [remote] [branch]Copy the code
Copy the code
Upload the local branch to the remote repositoryCopy the code
$ git push [remote] [branch]Copy the code
Copy the code
Push current branch to remote repository forcibly, even if there is conflictCopy the code
$ git push [remote] --forceCopy the code
Copy the code
Push all branches to the remote repositoryCopy the code
$ git push [remote] --allCopy the code
Copy the code
- undo
Restore the specified file from the staging area to the workspaceCopy the code
$ git checkout [file]Copy the code
Copy the code
Restore the specified files of a COMMIT to the staging area and workspaceCopy the code
$ git checkout [commit] [file]Copy the code
Copy the code
Restore all files from the staging area to the workspaceCopy the code
$ git checkout .Copy the code
Copy the code
Reset the specified file in the staging area, same as the last commit, but with the same workspaceCopy the code
$ git reset [file]Copy the code
Copy the code
Reset the staging area and workspace as the last COMMITCopy the code
$ git reset --hardCopy the code
Copy the code
Reset the pointer to the current branch to commit, and reset the staging area, but the workspace remains the sameCopy the code
$ git reset [commit]Copy the code
Copy the code
Reset the HEAD of the current branch to the specified COMMIT, and reset the staging area and workspace to the same as the specified COMMITCopy the code
$ git reset --hard [commit]Copy the code
Copy the code
Reset the current HEAD to specify commit, but leave the staging area and workspace unchangedCopy the code
$ git reset --keep [commit]Copy the code
Copy the code
Create a commit to revoke the specified commitCopy the code
All changes of the latter are cancelled out by the former and applied to the current branchCopy the code
$ git revert [commit]Copy the code
Copy the code
Uncommitted changes are temporarily removed and moved in laterCopy the code
$ git stashCopy the code
$ git stash popCopy the code