Configure . gitignore to not upload certain files

Asked

Viewed 39,830 times

11

I am developing a project. Net and would like to add some files to not go up on Github through the .gitignore. I started researching about and saw some solutions, of which I did not understand.

So first, I can add all obj and bin files into my . gitignore, no problem will happen?

Second, considering the structure:

-Aplication
| -src 
| | - Domain
| | | - bin
| | | - obj

How would I ignore this whole folder bin and the whole folder obj?

  • 2

    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

  • @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

3 answers

16


If the .gitignore is at the same level as the folder Application then add this to the .gitignore:

Aplication/src/Domain/bin/*
Aplication/src/Domain/obj/*

And save the document, check git, so you should only ignore the contents of the folders.

If you want to ignore the content and the folders also, do this:

Aplication/src/Domain/bin/
Aplication/src/Domain/obj/

7

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 , 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 ):

./.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 .gitignoredistinct 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

5

What you add in the . gitignore file will not be uploaded to your git repository.

As described in official document: "The gitignore file specifies intentionally unreversioned files that Git should ignore. Files that are already being versioned by Git will not be affected."

So you can create . gitignore at the root of your project, and for your structure, put:

# Linhas iniciadas em # são comentários
src/Domain/bin/
src/Domain/obj/

This will ensure that the bin and obj folders, and consequently all of their contents, will not be sent to the server.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.