preface
Git Git Git Git Git Git Git Git Git Git
The flow chart of the Git
Differences between Git and SVN
Git Git
Create a branch
Git branch user-infoCopy the code
Create a branch and switch to the currently created branch
Git checkout -b user-infoCopy the code
Switch branch
Git checkout user-infoCopy the code
Deleting a Local Branch
Note: The deleted branch can only be deleted on the parent branch
Git branch -d user-infoCopy the code
Update the list of remote branches
Careful operation
git remote update origin --prune
Copy the code
Example Delete the remote branch user-info
Careful operation
git push origin --delete user-info
Copy the code
Remove files on branches
Git rm user-info.vueCopy the code
Submits the file to the specified branch
Commit user-info to the primary branch
git push user-info master
Copy the code
Merging branches
Merge the user-info branch into the merge
Git merge user-infoCopy the code
Check the status
git status
Copy the code
See the branch
git branch
Copy the code
View all branches
git branch -a
Copy the code
Merge conflicts
1Go to the branch to merge. If you want to merge the branch to master, go to the master directory2Check whether all branches have pulled down git branch -a3Git merge Specifies the git merge branch name4Git status5If there is a conflict, resolve the conflict through the IDE;6After the conflict is resolved, commit the conflicting file to the staging area7Git commit -m git commit -m"Note"Git will automatically submit the merge result to the local repository as a comment.8Local repository code commit remote repository git push git merge branch to branchCopy the code
The add file
Add all files in the current directory to the temporary storage area
git add .
Copy the code
Add specific files
Note that the file is added under the user-info parent file. If the file is not added on the parent element, please use the path to add the corresponding file
git add user-info.vue
Copy the code
Commit code (note the commit branch)
Generally speaking, one module corresponds to one branch
git commit -m 'First version Submission'
Copy the code
View submission History
The author, time, submitted branch, etc., will be displayed. If you use git log in the Terminal of IDEA, enter wq to exit.
git log
Copy the code
Set the code tag tag
A tag is a snapshot of the version library. When releasing a version, we usually put a tag in the version library first, so that we can uniquely identify the version at the time of the tag. Whenever you take the version of a label in the future, you take the historical version of that label moment.
Add a tag to the latest commit
git tag -a v1. 0
Copy the code
View all labels
git tag
Copy the code
Check for a concise version of the submission history
git log --oneline
Copy the code
Change the location of HEAD
Caution is often used to restore to a previous version
- Viewing the Version Number
git log
Find the current version number and the version number to restore - use
Git reset --hard 1faa6d9
git push
Commit changes, an error message indicating that the version is older than the remote repository, passgit push -f
Forced to push
Flexible management of local development
Git rebase -i merges locally committed code into one
- Switch branch
git checkout master
- Pull the latest branch state
git pull
- Switch to the local branch
git checkout user-info
- Merger submitted
git rebase -i HEAD~2
, 2 indicates the combination of two - Base the current operation branch on the target branch (master)
git rebase master
- Connect local and remote branches
rebase --continue
- Let’s go back to the main branch
git checkout master
- Merge the local branch onto the primary branch
git merge user-info
- Upload the local branch to the remote repository
git push
Keep adding ~, too many, remember the commonly used good