Java technology stack
www.javastack.cn
Follow to read more quality articles
Can't Git submit an empty directory? I am drunk too!
background
When I submitted a file recently, because of the empty Maven project structure, I found that the Git empty directory cannot be submitted alive or dead. I thought I had ignored it in the .gitignore file. I checked it on the Internet and it turned out that this happened.
For example, with a git status
view state:
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
Empty directory can not be git
induced.
solution
The most popular method is to create in an empty directory .gitkeep
or .keep
an empty file, or .gitignore
files, this is just a convention empty directory to identify the file name, in fact, in addition to occupying an empty directory to identify what the other did not use eggs.
We then create an empty file in the empty directory:
touch .gitkeep
Then use the git status
View Status:
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/
nothing added to commit but untracked files present (use "git add" to track)
You can now be induced to src
catalog a.
Also note, the projects .gitignore
do not ignore this file. If necessary, public concern number Java technology stack may obtain a copy of the recommended .gitignore
generic file.
WHY
This kind of solution feels a bit nonsense. Why can't I submit an empty directory? You must put a file. Putting an irrelevant file feels a bit nonsense.
So I checked the information again with suspicion, and I found an explanation in the following link:
https://git.wiki.kernel.org/index.php/GitFaq#Can_I_add_empty_directories.3F
Probably, Git was originally designed to index files, so Git only cares about files, not files, and directories.
Is this a design problem of Git?
Finally, have you encountered this kind of egg pain? Do you have other solutions? Welcome to leave a message to share~
Later, I will share some practical dry goods of the modification history record that I usually use, such as how to modify the history submission information, merge multiple submissions, etc., pay attention to the public account Java technology stack for the first time push.
Old irons, find it useful, click on it to watch and forward with support!
Pay attention to the Java technology stack to see more dry goods
Click the original text to get more benefits!