Git comb I: Foundation


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 usegit addCommand, the contents of the workspace are updated to the staging area.
  • Version libraries: Usinggit 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.

Git comb I: Foundation

Frequently used commands

Submission related

Common commands for code submission aregit addgit commitgit pull (--rebase)git push

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 usegit pull --rebase, submit the record more clearly.

General rollback

1. Code has not been committed

It’s just a small thing when you don’t submit it. Depending on circumstancescheckoutreset --hardstashOrders can be used.

2. The code has been committed and has not been pushed

Usually usedgit 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

Usually usedgit 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.

Recommended Today

Single and multiple buttons are styled with pictures

I’ve always seen people asking how to style and enlarge the buttons of radio buttons and multi buttons? Let’s share an example I did. 1. First make the button into a picture  2.html page Copy code The code is as follows: <!DOCTYPE HTML> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <script type=”text/javascript” src=”jquery-1.10.2.min.js”></script> <script type=”text/javascript”> […]