Git's .gitignore file, tag management, and aliasing commands


insert image description here

1 Introduction

This article mainly explains some important knowledge that is easily overlooked in Git: .gitignorefile, label management and aliasing commands.

2. .gitignore file

When creating a new warehouse, there is an add .gitignoretemplate:

insert image description here

.gitignoreis a configuration file that specifies Git to ignore specific files or folders. You can tell Git which files should not be brought into version control by listing the names, patterns, or wildcards of the files or folders to ignore in the file.

.gitignoreThe role of the file:

  • Git will automatically ignore files or folders specified in the file when executing the git statusor command.git add.gitignore
  • Prevent sensitive information and temporary files from being accidentally committed to the version control system.
  • Improve the cleanliness and maintainability of the code repository.

.gitignoreSome usage scenarios for files:

  1. If you want to ignore, you can directly write the file name, you can directly write the file name/you can also use a relative path or an absolute path to specify the location of the file or folder to be ignored.
  2. If a certain type of file is ignored, you can use wildcards *to match any character, or you can use ?to match a single character.
  3. If you use wildcards to ignore files, but you don't want to ignore them all, you can use !the corresponding files and folders without ignoring
  4. If a file is ignored, but it is not easy to go to .gitignore to check the reason, you can use git check-ignore -v [文件]the reason of printing ignore
  5. Lines starting #with are considered comments and will not be processed.

.gitignoreDocumentation rules:

  • Each line represents an ignore rule.
  • You can /start with to indicate a path relative to the root directory, or omit /to indicate a path relative to the current directory.
  • You can use /trailing to ignore folders, or omit /to ignore files.

3. Tag management

In Git, tags (Tags) are used to mark specific commits (commits) with identifiable marks, and can be used to identify important nodes such as version numbers and release versions. Tags are immutable, i.e. once created they cannot be modified.

Create tags:

git tag -a [版本] -m "描述"
# -a(可不加) :选项意为"创建一个带注解的标签"。
# -m(可不加): 用于描述标签

View existing tags:

git tag

Add tags to previous commits:

git tag [版本] [commitID]

View label descriptions:

git show [标签]

Delete tags:

git tag -d [标签]

In our remote repo, there is also a label option

insert image description here

We can push the tags in the local warehouse to the remote warehouse

The command is as follows:

Push a tag:

git push [远程仓库名] [标签名]

Push all tags at once:

git push [远程仓库名] --tags

If you want to delete the tags that have been pushed to the remote warehouse, there are two steps:

  1. git tag -d [标签]command to delete the local label
  2. usegit push [远程仓库名] :[版本]

4. Alias ​​the command

In Git, there are some long commands that are cumbersome to type and easy to make mistakes. Therefore, you can simplify commonly used commands and improve work efficiency by setting aliases.

The command is as follows:

git config --global alias.<alias> <command>
  • –global (optional): set the global command alias
  • <alias> : Indicates the alias you want to set
  • <command>: raw Git command

After setting the alias, the original Git command can still be used

Precautions:

  • When setting up an alias, it's best to choose a name that won't conflict with existing Git commands or other aliases.
  • Aliases can contain any valid Git commands and options, and parameters can also be used.
  • You can use git config --global --unset alias.<alias>the command to remove an already set alias.

This is the end of the article, thank you for watching!
insert image description here

Guess you like

Origin blog.csdn.net/m0_63463510/article/details/132008116