I have a colleague using it these two days.
git push -fI have flushed away several submissions from the remote end, and I am forced to sort out relevant issues.
Basic knowledge of GIT
The detailed course of GIT recommends Liao Xuefeng’s git course. Here is a brief review of relevant knowledge.
Git management of local content, there are workspace, staging area, version library concept.
- Workspace: it’s actually the document we can see directly. Our changes are directly reflected in the workspace.
- Staging area: stored in
.git/indexDirectory, we use
git addCommand, the contents of the workspace are updated to the staging area.
- Version libraries: Using
git commitThe contents of the staging area are updated to the version library.
In general, there is always a remote warehouse in development.
git pushThe command pushes the contents of the local repository to a remote repository.
The figure below shows the state switching of GIT.
Frequently used commands
Common commands for code submission are
git pull (--rebase)、
I won’t talk about the other few. I’ll talk about the rebase parameter in pull.
If there are new submissions at the local and remote ends, and the rebase parameter is included in pull, rebase is used at the local and remote ends. After the conflict is resolved, it is equivalent to moving the local submissions to the remote submission for several times, and the submission records will be clearer.
When you pull without the rebase parameter, you do a merge. The local and remote commits will be divided into two lines and finally merged into a new merge node.
In terms of my personal experience, it is usually more recommended to use
git pull --rebase, submit the record more clearly.
1. Code has not been committed
It’s just a small thing when you don’t submit it. Depending on circumstances
stashOrders can be used.
2. The code has been committed and has not been pushed
git resetRoll back to the specified commitid, and pay attention to the distinction between mix and hard. Mix is used when you want to keep the code, and you can force merge when you don’t keep the code.
3. The pushed code needs to be rolled back
git revertCreate a rollback commit. The basic principle is not to affect remote submission records.
Why is there a design of temporary storage area
Why do I need git add before git commit? -Ivony’s answer – Zhihu
In essence, it is to be able to select some files to submit under the command line.