Git git git git git git git git git git
Introduction to the
Git was the version control software Linus was unhappy with more than a decade ago. Unlike traditional, “centralized” version control software such as CVS/SVN, which stores diff based updates, Git believes that every file is immutable once written to an object database, and that any minor modification creates a new object in the database. The id of the object is its SHA1 hash. With this foundation, file objects (BLOBs) can be organized into trees (merkle trees, to be more precise), and a COMMIT is the process of generating a new tree based on information from the changed file. The new tree shares the same subtree as the old tree, and only the changed parts are forked. After a long operation, the object database has an infinite number of trees that form a Merkle DAG. By using references such as HEAD, Heads/Master, tags/v0.1, Git makes it easy to track the exact state of each tree that a user is interested in.
The principle of
First git init generates a new repository.
Git automatically creates the following directory: In git’s object database, a new file is created.
The contents of this file are the contents of readme. md with the filename as a base16-encoded string after its SHA1.
Note that a two-tier directory structure is used so that the directory does not become overloaded when there are many objects. This design pattern can be seen in many systems, such as nginx cache.
Git has four main types of objects:
Blob: Object stores the actual file
Tree: directory structure for object storage files
Commit: Object store commit information (mainly the current root and the root of the previous tree)
Tag: Stores version information, equivalent to a commit in the object library to explicitly flag that the file name does not exist in the BLOB object, but in the tree. This has two advantages: 1) Even if multiple copies of the same content are made, only one copy of the data is stored – this is more common in binary files, such as images; 2) Changing the file name only generates a new tree, not a new blob operation.
Git configuration
Git’s Settings file is.gitconfig, which can be in the user home directory (global configuration) or in the project directory (project configuration).
git config --global user.name "@username" git config --global user.email "@email" git config --global color.ui true git config --global alias.co checkout git config --global alias.ci commit git config --global alias.st status git config --global alias.br branch git config --global core.editor "mate -w" # The configuration fileCopy the code
Git Git
Git init # will be initialized to the current directory git repository git clone https://github.com/KKDestiny/wechat_oauth2.0.git # to the current path git clone remote warehouse help < command > # Git show $id git co -- <file Git rm <file> git rm <file> Git reset <file> # git reset --. # git reset --hard # Git ci <file> git ci. Git ci-am "some comments" git ci --amend # git revert <$ID > Git diff git diff <$id1> <$id2> Git diff <branch1>.. <branch2> # Compare staged Git diff --cached git diff --stat # Only compare statistics to view commit records Git log -p git log -p git log -p git log -p --stat # View commit statisticsCopy the code
Git commit code specification
<type>(<scope>): <subject> 1. Type feat. Fix bugs in docs style. 2. Scope is used to indicate the scope of the commit impact, such as the data layer, control layer, view layer, etc., which varies from project to project. Db, Controller, views 3. Subject indicates a short description of the commit purpose. The value contains a maximum of 50 characters. "Module: Popbox"Copy the code
Git ignores file formats
# Created by .ignore support plugin (hsz.mobi)
### Java template
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
.logs/*
**/*.iml
# Package Files #
*.jar
*.war
*.ear
target
.idea
.DS_Store
exports
# virtual machine crash logs, see
http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.tags
.tags_sorted_by_file
Copy the code
Git local branch management
Git br <new_branch> # merged git br <new_branch> # merged git br <new_branch Git co -b <new_branch> # create new branch git co <new_branch> Git co -b <new_branch> <branch> Git co $id -b <new_branch> Git br -d <branch>Copy the code
Git remote branch management
Git pull --no-ff # git pull Git co --track origin/branch # Git co-b <local_branch> origin/<remote_branch> Git push -u origin master git push -u origin master git push -u origin master Git push origin <local_branch> Git push origin :<remote_branch - d < branch >), Git remote add origin Git remote add origin Git remote add origin git@github:robbin/robbin_site.git # add git remote set-url origin [email protected]:robbin/robbin_site.git # Git clone --bare robbin_site robbin_site.git # Git &&cd robbin_site.git &&git: run the following command to create a pure repository: SCP -r my_project.git [email protected]:~ # Git remote add origin [email protected]:robbin/robbin_site Git push -u origin develop # commit local develop branch to remote develop branch for the first time Git branch --set-upstream master (" upstream master ") git branch --set-upstream master Origin /master git branch --set-upstream develop origin/master git branch Check all local branches. Git status Check the current status Commit -am "init" commit and comment git remote add origin [email protected]:ndshow git push origin master Git push origin master:develop git push origin master:hb-dev Git checkout /dev --track origin/dev -- git checkout /dev --track origin/dev -- git checkout /dev -- git checkout /dev Switch to the local dev branch git remote show see git add remote repository. Git rm file name (including path) to delete the specified file from the git git clone git://github.com/schacon/grit.git Git rm [file name] delete a file git commit -a Commit all changes to the current repos git Git commit -v "git commit -m "This is the message describing the git index git commit -v Git commit -a -a stands for add, Git commit -a -v git log git diff git rm a.a Git rm --cached a.a Remove the file (from staging and workspace only) git commit -m "remove" remove the file (from git) git rm -f a.a Forcefully remove modified files (removed from staging and workspaces) Git diff --cached or $git diff --staged to view updates that have not yet been committedCopy the code
Git branch merge and rebase
Git merge <branch> Git rebase <branch> git co <branch> && git rebase master && git co master && git merge <branch>Copy the code
Git Patch Management
git diff > .. Git apply... Git apply --check... /sync.patch # Test whether the patch is successfulCopy the code
Git staging management
Git stash drop drop git stash drop drop git stash dropCopy the code
conclusion
Git commit -am "fist" Git add. Git commit -m Git add changes a file from its modified state to its provisioned state so that it can be committed to the local repository. Git branch -d branch_name git push origin Git branch branch branch_name View all branches. Git branch -va Merge branches. Git branch -a View all branches Git branch -d master develop Delete the local library develop. Run git reset --hard HEAD~n. Git reset --hard SHA # go back to the commit version of SHA. Stack operation git stash # Create a temporary stack cache git stash list # View the stash stack git stash pop Git stash Clear # Stash stack. Git stash push -u origin master -f Force upload to replace the original data git stash pop Pop the file from the temporary space rename the branch git branch -m main master git push -u origin master ##Copy the code