How does git ignore files that do not need to be submitted? (ignore commits.gitignore)

Problem description :

In the process of using Git, we do not want to submit files such as target, .idea, etc. to the code warehouse, but if these files are not added to the temporary storage area, switching branches will report an error of Move or commit them before Pull git (as follows Figure), how should we solve it?

Solution:

1. Create a .gitignore file in the following directory (same level as src), which is git's ignore submission configuration file

Note: Create a new gitignore file instead of configuring it directly in the .gitignore file under .idea

2. Add directories or files that need to be ignored and submitted, the configuration method is as shown in the figure

The beginning of "/" indicates the entire directory; the asterisk "*" wildcards multiple characters;

A question mark "?" wildcards a single character 

.gitignore rules not taking effect?

.gitignore does not take effect because the ignored files have been tracked, and .gitignore can only ignore the files that were not tracked. The solution is to delete the local cache first (change to untracked state), and then submit:

git rm -r --cached 文件名
git add .
git commit -m '描述'
git push

After this set of operations, the configuration will take effect, and those files that we don’t need that already exist in the remote warehouse will also be deleted

Guess you like

Origin blog.csdn.net/w20001118/article/details/128407646
Recommended