0

My current project has a property file which includes some configurations of the project.

For a example

server.jboss.home.dir=/home/user1/apps/apache-tomcat-7.0.54

We need to edit these configuration in locally to run the program.

But the problem is when someone makes a commit he will commit his local changes in property file also including other changes. So when we need to pull changes we have to stash our local property file changes and change them after pull.

Is there a way in git pull (or any command ) for prevent updating specific local files ?

  • got the answer from this thread http://stackoverflow.com/questions/13674014/how-to-prevent-git-pull-from-overwriting-a-file –  Sep 18 '14 at 09:53
  • Possible duplicate of [How to prevent git pull from overwriting a file?](https://stackoverflow.com/questions/13674014/how-to-prevent-git-pull-from-overwriting-a-file) – pirho Oct 28 '17 at 11:20

2 Answers2

2

Add it to gitignore.

   gitignore - Specifies intentionally untracked files to ignore

Create a file called .gitignore in the root of the project, or in the location where the file you wish to be ignored resides, and add the relative path to that file from the .gitignore file.

If you need a sample configuration file in the repo, people generally opt for a naming convention to include it alongside where the ignored file is. Commonly:

config.ini < ignored
config.dist.ini < sample

or

config.sample.ini < sample

An alternative is to have a global configuration file that contains items which are needed but don't relate to each developer's setup, and a local configuration file that can optionally override items from the global one. For example, the global one may contain a version number for the project, and the local one a database password. That'd require a little more setup in your application code though.

You may also wish to view this question: How to make Git "forget" about a file that was tracked but is now in .gitignore?

Community
  • 1
  • 1
bcmcfc
  • 25,966
  • 29
  • 109
  • 181
  • 1
    As I know we can only exclude files from commits using 'gitignore' file. But we cannot prevent updating local files in 'git pull' using 'gitignore'. Am I wrong? –  Sep 18 '14 at 09:05
  • Once the file you don't want to be changed is removed the repo it shouldn't be an issue. – bcmcfc Sep 18 '14 at 09:44
0

For that is the gitignore file. Make a file caled config.template for example. Check them in and when a people clone the project he can copy the template to his own project.

In the .gitignore file you add the file.

/your/path/yourfile

Then the file is not in the repository.

http://git-scm.com/docs/gitignore

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • 1
    As I know we can only exclude files from commits using 'gitignore' file. But we cannot prevent updating local files in 'git pull' using 'gitignore'. Am I wrong? –  Sep 18 '14 at 09:14