1. Introduce the git

Git is an open source distributed version control system designed to handle any project, small or large, nimbly and efficiently. We use a tool very frequently in our development and management process.

1.1 However, our general workflow with Git is as follows:

Cloning a Git resource as a working directory. Adds or modifies a file on a cloned resource. If someone else changes it, you can update the resource. View the changes before committing. Commit the changes. After the modification is complete, if an error is found, you can undo the commit and modify and commit again

1.2 Another development mode, similar to GitHub’s development mode:

Create a main warehouse. Each developer forks a copy of the development library. After the development, the developer develops in the code that he or she forks

2. Basic use

In the process of using the forgotten operation command, use -h to check

2.1 Operation of the remote warehouse:

Origin is the default name that points to a remote code base and can be changed; You can also add a new point to the git remote show origin to view the central repository information. Git remote can list the current repository name git remote-v list the current repository list git remote rm Git branch develop git push -u origin develop git branch develop git push -u origin develop Git checkout -b develop origin/develop git remote prune origin removes local branches that do not already exist on the remote side

2.2 Pull command

Git fetch (git fetch) git fetch (git fetch) git fetch (git fetch) git fetch (git fetch) git fetch (git fetch) Git push/git push/git push/git push/git push/git push Git checkout -f branchname: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  git fetch origin git reset --hard origin/test

2.3 Develop a complete command process

Make sure the Develop branch is up to date before merging with the main branch git pull origin develop Git fetch --all git checkout develop git merge some-feature git push git branch -d some-feature

2.4 Branch operation

Git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch: git branch Git push origin :br-1.0.0

2.5 File comparison

The key to mastering the git diff command is to understand the four states of a Git file and where the file is located. There are three areas where the file resides: workspace, staging area, and warehouse. The flow direction of the file is created by the workspace, add into staging, and commit into the repository. For files that have been modified, you may want to see exactly what has been modified. The git diff command can be used to compare the current workspace (not committed to staging) with staging (already committed via git add and git commit). Specific modification changes. Git diff is compared from right to left. Git diff compares staging and workspace files. Git diff - Cached compares the repository to the staging area file. Git show * git show * git show * git show * git show

3. Git back and undo

3.1 the git rolled back

In collaborative development, it is easy to have code conflicts and overwrite other people's code if git is not merged properly. Add and Commit, then git pull-->, then commit -->, then push git fetch --all does not show the current update, and git log does not see it. Commit_id = commit_id = commit_id = commit_id = commit_id = commit_id Git reset --hard commit_id git push origin HEAD --force git rebase -- abort Git reset --hard hash or git checkout <sha1-of-a-commit > > Git reset --soft HASH # Returns to a node. Retain modifications to git rebase -- abort back to git checkout before the merge. Git stash = git stash; git stash = git stash; git stash = git stash Restore with Git Stash Apply.

3.2 Undo files, etc

Git reset HEAD git reset HEAD git reset HEAD git reset HEAD git reset HEAD git reset HEAD Git reset the HEAD - filename / / cancellation of all the modified but fails to submit the file modification, but does not include additional files git checkout. / / cancellation of the specified file modification, Git checkout [filename] git checkout [filename]

4. Tag

Git -a 0.1-m "Initial public release" master git push --tags/git push origin 0.1 Git push origin :refs/tags/ tag name

5. Git selection

Git cherry-pick < commitid > # git cherry-pick < commitid > # git cherry-pick < commitid > # Go to the master branch, git checkout master, git cherry-pick f

Git merge Git rebase

The Merge command retains the historical time for all commits. Everyone's code submission is different. These times, though, don't mean anything to the program itself. But the merge command is intended to keep these times unmodified. This results in a network history based on the merge time. Each branch continues to keep its own code record, and the main branch keeps only the history of the merge. Subbranches can be deleted at any time. When a submolecule is deleted, the only record you can see is that you merged a branch into a branch. This historical description is basically meaningless. Rebase, which will always put your latest changes to the forefront. For example, if you rebase the main branch, all of your changes will precede all of the changes currently made by the main branch. You'll have more confidence that your code will run smoothly. After your own testing, you can safely merge the code into the main branch.