0

In my project I would like to ignore a single line of code, because it contains a directory which is different for every user of the repo.

I have found a useful answer for my problem, however I don't know how to apply this to my own problem.

The line I need to ignore is as follows: MyMesh.loadMesh("D:/Software Projects/OpenGL/Raytracing-Project/dodgeColorTest.obj", true);

So what i would like to know is what i have to insert in the $ git config filter setting, for both the clean and smudge case.

Community
  • 1
  • 1
  • 6
    Move the string into a configuration file, put the configuration file into `.gitignore` (if it isn't already there). This is the correct way to do it. Any other hack you may use is just a ticking bomb waiting to blow up when you expect less. – axiac Jun 04 '15 at 13:51
  • @axiac what kind of configuration file? Can you show me an example? – Robin van Heukelum Jun 04 '15 at 14:11
  • @RobinvanHeukelum, literally any kind of config file. A plain text file, JSON, YAML, XML, ... Choose one that's commonly used with your stack or pick one that you like. – ChrisGPT was on strike Jun 04 '15 at 14:13
  • Since you didn't specify the language you are using (it looks like `C#` or `Java` to me but I don't know these languages), I added an answer that explains how to do it in `C` or `C++`. It shouldn't be very different in `C#` or `Java` (apart for the syntactical differences). – axiac Jun 04 '15 at 14:43

1 Answers1

1

The standard solution for your problem is to move the string into a configuration file and add that file to .gitignore. Also, put a renamed copy of the file into the repository together with explanation about how to use it.

The format of the configuration file and the way you use it depend on the language you are using.


For C, C++ and similar languages it can be as simple as a .h file that contains something along these lines:

/**
 * This file contains various constants (paths, for example) that are specific
 * to the computer where this code is compiled.
 *
 * Make a copy of this file as 'config.h' and change it to match your system.
 */

#ifndef __CONFIG_H__
#define __CONFIG_H__


/* The path to the OBJ file used by blah-blah-blah feature */
#define OBJ_PATH "D:/Software Projects/OpenGL/Raytracing-Project/dodgeColorTest.obj"


#endif

Name it config.h.dist (or use another name that is more appropriate to your project and coding style) and add it to the repository.

Make a copy of it as config.h and add config.h to .gitignore.

Put #include "config.h" into the file from where you extracted the code above and replace the concrete file path with the symbol defined in config.h:

#include "config.h"

MyMesh.loadMesh(OBJ_PATH);

Use the technique to extract from the code into config.h all the values that may be different on the systems of your workmates. Don't forget to add them to config.h.dist too, with a relevant description about their types and the values they may have.

axiac
  • 68,258
  • 9
  • 99
  • 134
  • Why do you name the second config file with the .dist extension? – Robin van Heukelum Jun 04 '15 at 15:09
  • 1
    It comes from "distribution". It is the one that you distribute to others; they use it as a template to get their own version that fulfills their needs. Read [this SO question](http://stackoverflow.com/q/16843080/4265352) for a more detailed explanation of the idea. – axiac Jun 04 '15 at 15:50