File does not appear for comitt in Smartgit

Asked

Viewed 65 times

3

I have a persistence.xml file that is the default application, but each developer uses a different one and always has one that comita this persistence unintentionally. I was wondering if there’s a way to make sure that this file, even if it’s changed, doesn’t show up for commission.

  • It’s not just adding it to . gitignore?

  • @LINQ do not know, even using git local not github to use . gitignore?

2 answers

3

First you create an example file of this persistence.xml, for all who are developing know that it is necessary, for this you can create a file persistence.exemple.xml. In it you put the file structure without the values. Example:

<persistence-unit name="Hello" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <properties>
        <property name="hibernate.show_sql" value="" />
        <property name="javax.persistence.jdbc.driver" value="" />
        <property name="javax.persistence.jdbc.url" value=""/>
        <property name="javax.persistence.jdbc.user" value="" />
        <property name="javax.persistence.jdbc.password" value="" />
        <property name="hibernate.dialect" value=""/>
        <property name="hibernate.hbm2ddl.auto" value=""/>
    </properties>
</persistence-unit>

This file you should commit to. Now what already existed you need to tell git not to watch it anymore. You can do this with this command: git rm persistence.xml

Now to make sure no developer commits the file you create a file called .gitignore at the root of the project and inside it put all the files that should not go to git. In this case would look like this your file .gitignore:

persistence.xml

2


As already stated in the comments, you can make use of the .gitignore.

The .gitignore is a file in which you specify other files that should not be screened, that is, it will ignore whether or not there are changes in these files.

If a file is already in your remote repository, say local.config, and you add it to .gitignore, the file will continue in the remote repository, but any local changes made to it will not be reflected in the remote repository as it is no longer being "tracked".

Search pattern

Every line in the file .gitignore specifies a path that follows a pattern described in the documentation:

  • Empty lines are ignored, so you can use them as a separator between groups of files;
  • # at the beginning of the line makes it a comment;
  • spaces at the end of the line are ignored;
  • ! serves to ignore a pattern. For example, diretório/ ignore all files from the specified directory, but you can use diretório/!arquivo to remove the arquivo from the ignore list;
  • / is used as a directory separator, if the bar / is at the beginning or middle of the pattern, means this pattern will be applied in relation to at the directory level .gitignore is;
  • / at the end of the pattern indicates that it is a default for directories, otherwise it may be either directory or file;
  • * corresponds to any characters except the bar /;
  • ? corresponds to a single any character, with the exception of the bar /;
  • **/ at the beginning corresponds to "any directory";
  • /** at the end corresponds to "everything inside the directory";
  • /**/ corresponds to "zero or more directories".

Example

Given the following file and directory structure:

meuprojeto
├── app
│   ├── paginas
│   │   ├── .config
│   │   ├── contato.html
│   │   ├── home.html
│   │   ├── home.css
│   │   ├── home.js
│   │   ├── teste
│   │   ├── teste.html
│   │    
│   ├── teste
│   │   ├── .config
│   │    
│   ├── debug.log
│   ├── error.log
│   ├── error1.log
│   ├── error2.log
│   ├── error30.log
│   ├── example.log
│   ├── main.log
│
├── .config
├── .gitignore

We could have the following on .gitignore:

# Ignorar qualquer arquivo ou diretório chamado `teste`, note que `teste.html` não é ignorado
teste

# Ignorar todos `.log` com exceção do `example.log`
*.log
!example.log

# Parar de ignorar os arquivos `error<identificador_1digito>.log`, note que `error30.log` continuará ignorado
!error?.log

# Ignorar o `.config` que está dentro de `paginas`
/app/paginas/.config

Browser other questions tagged

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