I would like to add a few more considerations than there are in the @Guillhermenascimento and of @Brunofelipe. These are general considerations of the structure of .gitignore
for extra reference/future reference.
As William said, you can mention on the way with *
to get the files. From his example:
Aplication/src/Domain/bin/*
Aplication/src/Domain/obj/*
But that asterisk is more powerful than just pointing out all files in one folder. And that’s because of the way .gitignore
is interpreted.
In the .gitignore
, you inform a set of paths. These paths are interpreted as glob
of shell
. This allows some cool things, such as for users of vim
:
.*.sw[po]
This indicates that every file hidden/started by .
, whose end is .swp
or .swo
, will be ignored.
In the vim
, an archive of swap is created at the time you edit a file. So when editing the file resposta.txt
, a .resposta.txt.swp
. If by chance the vim
stop unexpectedly (without deleting the temporary file .resposta.txt.swp
) and I open the file again resposta.txt
, the vim
will create the .resposta.txt.swo
and suggest redeeming the unapplied changes from .resposta.txt.swp
.
More about glob
:
Something that is very common is to find to ignore compiled files. In java, I usually put the following:
*.class
*.jar
*.war
But it can be dangerous if you use the maven
/graddle
wrapper. In such cases, it makes sense to commit the jar of wrapper. How to do this with .gitignore
? Simple, you can deny an exclusion by putting an exclamation !
at the beginning of the line:
*.class
*.jar
*.war
!.mvn/wrapper/maven-wrapper.jar
Note that the only jar
that will appear will be what is located in .mvn/wrapper/maven-wrapper.jar
.
It also has another interesting feature: ignore src/Domain/obj/
and ignore /src/Domain/obj/
has different effects. Why? Well, let’s go to the example.
Suppose we have the following modified files (considering .
the basis of the directory git):
./.gitignore
./src/Domain/obj/marmota.o
./test-project/src/Domain/obj/marmota-teste.o
If the content of .gitignore
be it src/Domain/obj/
, the only file that will be accused of change will be itself .gitignore
.
Now, if it’s /src/Domain/obj/
, then the files displayed will be the .gitignore
and the marmota-teste.o
.
When you put the bar at the beginning of the line, you are forcing the file being ignored to refer to the root where the .gitignore
.
One more last detail, you can specify .gitignore
distinct s by directory.
For example:
./.gitignore
./src/.gitignore
./resources/.gitignore
The first .gitignore
applies globally. The src/.gitignore
does not interfere with the folder ./resources
, and also the resources/.gitignore
does not interfere with the folder ./src
Try using this
.gitignore
when using projects in Visual Studio https://github.com/github/gitignore/blob/master/VisualStudio.gitignore it covers almost everything you normally don’t need to climb– Jeferson Almeida
@Jefersonalmeida mais prático fazer build out-of-Tree (in folder outside the project/ solution)...commonly used with cmake, with pure Visual Studio I don’t know if I can do
– zentrunix