git remote operation, push [push], pull [pull], ignore special files, configure aliases, tag management

Foreword:

If you have not read the basic operations of git in the previous chapters, it is recommended to read it first and then look at this remote operation. This way you will have a deep understanding of git~~

Next we discuss the main topic of this chapter:

Git is a distributed version control system that allows teams to collaborate on development and track code changes. Remote operation is an important concept in Git, which enables developers to share and synchronize code between different computers. I won’t introduce much here. You can go to Baidu to find it by yourself~~

This tutorial uses code cloud ( gitee.com ) to demonstrate

Create a new remote warehouse clone

  • The first thing you need to do is register an account of your own.
  • Then create a new warehouse

Insert image description here

Insert image description here

  • There are two ways to clone the repository locally, one httpsisssh

  • We don’t use it httpsbecause https is relatively simple.

  • Next we will use this sshto configure

    • Use ssh to clone the warehouse. Since we have not added the public key to the remote library, the cloning will fail. We will not demonstrate it here. Next, we will start configuring how to add the public key.
  • First open settings->ssh public key->public key

  • So where to get the public key here? Of course, it is on your own computer or remote server~~

Insert image description here

  • I demonstrated it here on my own computer, and the remote server obtains it in the same way~~
  • Enter the command, note: change it to your own email address~~
ssh-keygen -t ed25519 -C "[email protected]"

Insert image description here

  • Then the address will be displayed at the address in the picture above. Just find this folder. The second .pubsuffix is ​​the public key. We use Notepad to open it and copy the contents.

Insert image description here

  • Then paste it into the public key column of the website you just mentioned. Just write the title as you like.

Insert image description here

  • Finally, use ssh to clone

Insert image description here

  • OK, you can see that it has been successful~~

Insert image description here

push【push】

  • We modify the files in the warehouse

Insert image description here

  • and then add

Insert image description here

  • The last critical step ispush
git push origin master

Insert image description here

  • Then check the remote warehouse and you can see that it has been modified.

Insert image description here

Pull【pull】

  • We first directly modified the remote warehouse

Insert image description here

  • This time we made local modifications again, and then added

Insert image description here

  • Finally, I performed the submission operation and found that it could not be submitted because there would be a conflict.

Insert image description here

  • At this time, we need to first pull the remote warehouse
git pull origin master

Insert image description here

Insert image description here

  • Here we are back to the conflict, and then we need to manually modify it and then submit it.

Insert image description here

  • Then add and submit the operation

Insert image description here

  • You can see that it already exists~~

Insert image description here

Configure git

ignore special files

  • In daily development, we don’t want to submit some files to the remote warehouse, so what should we do?

    • At this time, we need to create a special file in the root directory of our warehouse .gitignoreand fill in the file names that need to be ignored. These files will be automatically ignored when git submits~~
  • Let's demonstrate

  • The representative here *is a wildcard, that is, .txtfiles with suffixes are ignored.

Insert image description here

  • Let's check the status of git and see if there is any文本.txtInsert image description here

  • Submit after adding again

Insert image description here

  • Come to our remote warehouse to check

Insert image description here

  • But sometimes, you just want to add a file to Git, but because the file is ignored by .gitignore and cannot be added at all, you can use -f to force the addition:
git add -f [filename]
  • Or you find that there may be a problem with the writing of .gitignore, and you need to find out which rule is written wrong. For example, if the a.so file
    is to be added, you can use the git check-ignore command to check:
git check-ignore -v file.txt
  • Git will tell us which line of rules in .gitignore ignores the file, so we can know which rule should be revised.

There are also times when we write rules to exclude some files, for example:

# 排除所有.开头的隐藏⽂件:
.*
  • But we found that the .* rule also excludes .gitignore. Although you can use git add -f to force it to be added, students with obsessive-compulsive disorder still hope not to break the .gitignore rules. At this time, you can add an exception rule:
# 排除所有.开头的隐藏⽂件:
.*

# 不排除.gitignore
!.gitignore
  • The way to exclude specified files from .gitignore rules is ! + file name, so you only need to add the exception files.

Configure aliases for commands

  • When using git, sometimes the command is too long and too troublesome. We can rename the git command into a short one. We do this:

  • For example, we will git statusabbreviate it asgit st

  • Change it here alias.to the name you want to change it to

git config --global alias.st status
  • --globalThe parameters are global parameters, which means these commands are available in all Git repositories on this computer. If not added, it will only work for the current warehouse.

  • In this way, the renaming can be successful, and the original name can also be used~~

Insert image description here

tag management

Understand labels

  • We can simply understand this label as commitan identification of a certain event, which is equivalent to an alias.
  • For things that are difficult to remember commit id, tags can solve this problem very well. Tags can locate an important version. Using tags, you can quickly locate that version, which is very convenient and fast.

Create tags

  • First check which branch you are on. If you need to tag which branch you need to switch to, which branch should you switch to?
git branch

Insert image description here

  • Then you can add a tag, just follow the tag name.
git tag v1.0
  • After tagging, you must check it
git tag

Insert image description here

  • This tag is not specified on which one it should be printed on, so it is the default. By default, it is printed on commit idthe latest submission.commmit

  • Then we need to commit idlabel the designation, and we can follow it withcommit id

git tag v0.9 741df88

Insert image description here

Note: The tags here are not listed according to time, but are sorted alphabetically.

  • We can also view tag information: showfollowed by the tag name, you can view specific information.
git show v1.0

Insert image description here

  • We can also specify tags with descriptions here, -a specifies the alias, and -m specifies the description text.
git tag -a [name] -m "XXX" [commit_id]

Insert image description here

Action tag

  • If the label is mistyped, we can also delete it -dfollowed by the label name.
git -d v0.8

Insert image description here

  • Because the created tags are only stored locally and will not be automatically pushed to the remote. Therefore, mistyped tags can be safely deleted locally

  • If you want to push a label to the remote, you can use the command

git push origin <tagname>

Insert image description here

  • We check the remote warehouse and see that the push has been successful.
    Insert image description here

  • If the local warehouse has many tags, they can be pushed to the remote end all at once.

git push oringe --tags

Insert image description here

  • It’s also quite perfect and has been pushed up.
    Insert image description here

  • If you want to delete a tag, you must first delete it from the local warehouse, and then push it again to update it.

  • Just follow the colon with the name of the label~~

git push origin :v0.9

Insert image description here

  • Let’s go to the remote warehouse again
  • It has been deleted perfectly~~

Insert image description here

Well, the remote operation of git ends here. I hope everyone can master these skills. This is a great improvement in ability. I also hope everyone will study hard! come on!

Supongo que te gusta

Origin blog.csdn.net/2201_76004325/article/details/135077091
Recomendado
Clasificación