Article directory
1 Introduction
This article mainly explains some important knowledge that is easily overlooked in Git: .gitignore
file, label management and aliasing commands.
2. .gitignore file
When creating a new warehouse, there is an add .gitignore
template:
.gitignore
is 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.
.gitignore
The role of the file:
- Git will automatically ignore files or folders specified in the file when executing the
git status
or 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.
.gitignore
Some usage scenarios for files:
- 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.
- 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. - 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 - 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 - Lines starting
#
with are considered comments and will not be processed.
.gitignore
Documentation 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
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:
git tag -d [标签]
command to delete the local label- use
git 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!