1, Merge branches
1. Create a dev branch from the master branch and switch to the dev branch
git checkout master git checkout -b dev
Where git checkout -b dev is equivalent to:
git branch dev git checkout dev
2. View branch
git branch
View the current local branch. A "*" in front of the branch indicates the current branch.
git branch -a
View all remote branches. A "*" in front of the branch indicates the current branch. Remote indicates that a remote branch exists, and no remote indicates that a local branch exists.
3. Modify code, commit code (the current operation is on the dev branch)
git add ifilldream.html git commit -m "submit document ifilldream.html"
4. Branch merge (merge dev to master)
git checkout master git merge dev
5. When the merge is complete, remove the dev branch
git branch -d dev
Note: when deleting the dev branch, note that our current branch cannot be the dev branch
Create branch summary
master Create branch: git checkout master git checkout -b dev //Create dev branch from master branch git push origin dev git add .. git commit -m "Comments submitted" git push origin dev
If Please tell me who you are. Appears in the git commit step, you need to enter your email address and user name, as follows
git config --global user.email "you@example.com" git config --global user.name "Your Name"
Note: the steps to push the local branch branch1 to the remote branch 2 are as follows:
git push origin branch1:branch2
6. Delete branch
git branch -d dev //Forcibly delete branch dev locally git push origin :dev //Push to remote
Note: when deleting a branch, the current branch cannot be a deleted branch
2, Conflict resolution
1. Conflicting files
<<<<<<< HEAD Creating a new branch is quick & simple. ======= Creating a new branch is quick AND simple. >>>>>>> feature1
Among them, git uses > > > > > to mark the part of the file where it conflicts with others. Code for others between > > > > >. If you keep your own code, just delete other people's code.
2. Submit after conflict resolution
git status git add *** git commit -m "fix remark" git push origin Branch name
3, BUG branch
1. Store changes: store the currently changed code and restore it later
git stash
2. Restore stored code
git stash pop //Delete the stash content while restoring //perhaps // Check all the local stash through git stash list. If I want to restore the first one, I will execute: git stash apply stash@{0} git stash apply //Restore the stash, but the stash content is not deleted git stash drop //On the basis of the above operations, remove the stash
Note: git stash list is to view all the stash lists
3. Empty the stash space
git stash clear
4. Differences between git stash pop and git stash apply
The original git stash pop stash@{id} command will delete the corresponding stash id from the stash list after execution. The git stash apply stash@{id} command will keep the stash id.
4, Version fallback
git reset --hard HEAD //Back to previous version
git reset --hard version number / / fallback to the specified version
git reflog //View previous version number (local commit)
git log //View version numbers and information (all commit: local commit other colleagues' commit)
5, Undo modification
1. Undo modification
git checkout -- ifilldream.html
There are two situations
> 1. has not yet executed git add operation. After executing the above operation, it will revert to the same version status as the version library.
>2. After executing git add but not yet executing git commit, the status after git add is restored
>Note: once you execute git commit -m "*", you can no longer use the above command to fallback.
2. Undo new file
For example, to create a new java.html page without executing git add, that is, it is not tracked by GIT. At this time, if you want to undo the new action, you can execute:
git clean -f ../java.html
3. Undo new folder
For example, to create a new folder "demo" without executing git add, that is, without being tracked by git, at this time, if you want to undo the new action, you can execute:
git clean -df ./demo
6, Back off the push ed version
git reset --hard Version number //Local fallback to specified version git push -f origin dev //Fallback remote to specified version
7, Local synchronization of remotely deleted branches
git fetch origin -p //It is used to clear the branches that have no remote information, so git branch-a will not pull the branches that have been deleted remotely
8, Delete local branches that do not correspond to remote branches
The branches that cannot be seen from the remote warehouse can be found locally through git branch-a. delete the local branches that do not correspond to the remote branches:
git fetch -p
9, View information about remote libraries and local branches
The branches that cannot be seen from the remote warehouse can be found locally through git branch-a. delete the local branches that do not correspond to the remote branches:
git remote show origin
10, Label management
1. Label the latest commit for the current branch
git tag v1.0.0
2. For example, on Friday, to label a commit on Monday, you should perform the following steps:
(1) . check the log log to find the corresponding commit version number
git log --pretty=oneline --abbrev-commit // It shows the following commit. For example, I want to tag the commit "34372b05"
44d2e20b fix bug
34372b05 fix bug
29554931 fix bug
(2) , label the specified commit
git tag v1.0.0 34372b05
(3) , the created label only exists locally and is pushed to remote
git push origin v1.0.0
(4) , one time push not pushed to remote local label
git push origin --tags
(5) , query all labels
git tag
(6) . query label details
git show v1.0.0
(7) , delete local label
git tag -d v1.0.0
(8) , delete remote label
//Delete local label first git tag -d v1.0.0 //Then delete the remote git push origin :refs/tags/v1.0.0
3. Create a label with a description, specify the label name with - A, and specify the description text with - m
//git tag -a version number - m remarks commit version number git tag -a v1.0.0 -m "version 1.0.0" 34372b05 (commit Version number) git show v1.0.0
More content, please pay attention to "WeChat dream".
Unified starting platform for WeChat public number "light dream to new", search attention to the public number, the first time to read the latest content.