From entering the pit to becoming a god, you only need to type the command once!

Technology has been advancing, time has been disappearing. Git has risen rapidly in recent years and has been adopted by more and more companies. A few days ago, some netizens almost started to work with colleagues. The reason is that the code is often inexplicably "lost". The reason is that Git is not familiar with it. After a conflict, the code of the person is directly overwritten. The subsequent "rollover accident"!

Git is simple and complex. I don't think you need to master all the commands in normal use, 20 commonly used commands are enough, and the rest can be collected, and you can do it with your hands when you flip through the notes!

The first command: git clone.

This command is not commonly used, usually after entering the company, clone the code to use. This command will generate a directory on the local host with the same name as the repository on the remote host.

From entering the pit to becoming a god, you only need to type the command once!

Git clone supports multiple protocols, in addition to HTTP(s), it also supports SSH, Git, local file protocols, etc.

From entering the pit to becoming a god, you only need to type the command once!

The second command: git init.

The git init command, as the name suggests, is to initialize a git repository. For example, if I create a new xttblog project locally, I can initialize it as a git repository for it.

From entering the pit to becoming a god, you only need to type the command once!

After git init, I often need to associate it with a remote warehouse, you can use the following command to associate.

From entering the pit to becoming a god, you only need to type the command once!

After the association is successful, we can execute git push to push the code.

From entering the pit to becoming a god, you only need to type the command once!

The third command, git pull.

This command is very simple, pull the remote code directly to the local warehouse. However, simplicity does not mean safety. It is often because of it that the code is "lost".

From entering the pit to becoming a god, you only need to type the command once!

After the code is updated, it may conflict with the code in the local warehouse. If there is a conflict, git may report an error saying "Automatic merge failed; fix conflicts and then commit the result". At this time, we can use the git diff command to view more conflict details.

From entering the pit to becoming a god, you only need to type the command once!

Then follow the prompts in git diff to modify the conflicting files. After deleting the conflict mark (<<<<<<<<<<<<<<<<< and >>>>>>>>>>>>>>>>>>>> lines). After resolving the conflict, you can execute git diff again to view the details of the conflict. If the conflict is completely resolved, you can execute the following command to submit the code.

From entering the pit to becoming a god, you only need to type the command once!

The fourth command: git branch.

Using this command will create a new branch. You can create a new branch from an existing branch. You can also use a specific commit or tag as a starting point to create a branch. If no specific commit ID is provided, the branch will be created with HEAD as the starting point.

From entering the pit to becoming a god, you only need to type the command once!

There are several important parameters for git branch, for example:

From entering the pit to becoming a god, you only need to type the command once!

The fifth command, git checkout.

This command is used to switch branches or restore working tree files. Git checkout is one of the most commonly used commands in git, and it is also a very dangerous command because this command will rewrite the workspace.

git checkout can also be used to retrieve some files in the index.

From entering the pit to becoming a god, you only need to type the command once!

It should be noted that when using git checkout, if the corresponding file has been modified, the modification will be overwritten.

The sixth command, git merge.

The git merge command is used to join (merge) two or more development histories together. For example, the branch merges I listed below.

From entering the pit to becoming a god, you only need to type the command once!

The seventh command, git reset.

One advantage of using version management tools is that you can take regret medicine. The git reset command is used to reset the current HEAD to a specified state. Generally used to undo some previous operations.

The git reset command has three main options: git reset --soft, git reset --mixed, and git reset --hard.

git reset --soft

Point the HEAD reference to the given commit. The contents of the index (temporary area) and the working directory are unchanged, and the state of the existing repository is minimally changed among the three commands.

git reset --mixed (the default mode of git reset)

The HEAD reference points to a given commit, and the contents of the index (temporary area) are also changed, and the contents of the working directory remain unchanged. This command will change the index (temporary area) to the state where you just temporarily saved all changes to the commit, and will show any changes in the working directory.

git reset --hard

The HEAD reference points to a given commit, and the contents of the index (staging area) and the working directory will change to the state of the given commit. That is, the modified content after a given submission will be lost (new files will be deleted, files not in the working directory will be restored, and the recycle bin has not been cleared).

From entering the pit to becoming a god, you only need to type the command once!

Below are some of the reset operations I often use.

From entering the pit to becoming a god, you only need to type the command once!

After writing here, I have read the above commands, and you have no problem using git in the company's daily development. In addition, it seems that there are only 7 commands above, but there are definitely more than 7 commands interspersed.

In addition, git has a lot of commands, such as: git config command, git help command, git init command, git add command, git clone command, git status command, git diff command, git commit command, git reset Command, git rm command, git mv command, git branch command, git checkout command, git merge command, git mergetool command, git log command, git stash command, git tag command, git fetch command, git pull command, git push command, git remote command, git submodule command, git show command, git shortlog command, git describe command, git rebase command. I haven't talked about most of them, but don't worry, I will give you a set of video tutorials below, so you can practice more.

Link address: https://pan.baidu.com/s/1rmT-wz-FwQ9Zjesm2t-jcw

Extract password: 61ju

If after watching this set of videos, you still can't figure it out. Then add my WeChat account "xttblog" and I will give you a few more sets, or I will pull you into the group and work hard together!

Guess you like

Origin blog.51cto.com/15127565/2665036