When submitting code with git command, I often encounter these errors. At first, I don’t know how to solve them. Now I want to write a note to record them and refer to them later.
Problem scenario
Scene 1:
- When you commit the code and push it to the remote, you get an error as shown in the figure, indicating that you have pushed the code before, and there is a conflict between remote and local
- Ggpush -f force push to remote, overwriting the previous push code
Scene 2:
- The error shown in the following figure is reported after rebase. This is because there is no pull update to the local code before cutting the branch, so the code conflicts when modifying the same file.
Git rebase –abort and git rebase –continue
- Git rebase — Abort the rebase operation. Git rebase is aborted. Then we go back to the main branch pull and rebase.
- Git rebase –continue git rebase –continue git rebase –continue git rebase –continue git rebase –continue git rebase –continue Git rebase –continue connects the local branch to the remote branch in a linear manner, and then exits back to the primary branch.
Scenario 3:
How to resolve conflicts found when submitting code to merge? To rebase the target branches, use the rebase command to merge the branches. After resolving the conflict, run git add. And git rebase –continue, push.
First, go to the target branch and pull the latest code (such as feature/ 3Q-S1-main), and then rebase the target branch, as shown below:Git rebase is aborted. Abort the rebase operation, and go back to the state before the rebase operation. Then go to vscode to fix the native code conflict. And then add submit
Git rebase –continue
At this point, the local branch code has been merged to the remote, and the previously submitted merge request is retained
supplement
Rebase vs. Merge
Reference: rebase:gitbook.liuhui998.com/4_2.html
Git Submission Process
New codebase:
- Git init creates a new code base
- Git init workspace Create a directory
- Git Clone project
- Git status Displays the current status of the repository and the files that have changed.
The new branch
- Git branch -a lists all local and remote branches
- Git branch guanliping A new branch that can stay in the current branch
- Git checkout -b guanliping new branch and switch to the new branch
- Git checkout guanliping
- Git push origin –delete deletes the remote branch
Commit code to the remote repository
- Add the code in your branch to the staging area git add.git commit
- Git status Displays the current status of the repository and the files that have changed.
- Go back to the main branch and git pull to update the remote code
- Git rebase git rebase git rebase git rebase
- Push to remote GGpush
Super handy with the Stash command
When you are still writing code, the requirements for this branch have not been completed, but you need to cut a new branch or switch to another branch to fix bugs, this time the native code has not been written and committed? Use the stash command to temporarily store the file.
- Git stash temporarily stores files that do not need to commit = git stash push
- Git Stash list Displays the Stash list
- Git status push -m ‘test’ custom message
- Git Stash pop holds the staging to file recovery and performs this operation recovery after committing the required files
- Git stash apply 0/1/2/3 temporarily stores the specified index to the stack
- Apply and push are both used to restore the temporary state. The difference is:
- Push frees the staging, but the stash list deletes the information
- Apply frees the staging, but the stash list keeps the information
- Git Stash clear Clears all temporary records
Summary of Common Commands
Git git git git git git git git git git git git git git git git git git git git git 5. Set user information git add | | git add. Git reset A --hard. $git commit -- amend-m [message] $git commit -- amend-m [message] $git commit --amend [file1] [file2]... Git git git git git git git git git git git git git < file >** View changes 13. Git fetch update remoteCopy the code
These are the common problems and git commands I have encountered in my work. Different projects and problems may have different solutions. Git command line tool is very powerful, proficient use is my goal, will continue to learn supplement.
Ggpush ggpull is short for git push and git pull
Attached document oh-my-zsh Git