1

For example, when I run my java project in my local machine ,I want always comment some code which is used for user identification ,but of course, these local modification should never be commited and pushed to the remote. What can I do ? I know .gitignore file, but as I know , this can only be used for files which is not versioned by git.So any suggestions?

wuchang
  • 3,003
  • 8
  • 42
  • 66
  • Possible duplicate of [Applying .gitignore to committed files](https://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files) – A.H. Apr 25 '18 at 05:41

3 Answers3

2

Instead of manually commenting the code, change the code to run or not those lines depending on a configuration value.

Store the configuration value into a configuration file that is added to .gitignore.

Put a version of the file containing the default values in the repository. Such a file usually have .dist appended to its file name and contains a comment that explain how to use it.

If there already exists such a pair of files in your project then use it; otherwise examine the existing configuration files, extract the values that depend on the environment (paths, connection parameters, authentication info etc) into a new file, add it to .gitignore, put reasonable default values into the the .dist version and add it to the repository.

axiac
  • 68,258
  • 9
  • 99
  • 134
1

If I understand you correctly, you want to untrack a file that has already been added/initialized to your repository

git rm --cached filename

Is the way to go. If you ever feel like getting this file back under tracking just do

git add filename
Tony Vincent
  • 13,354
  • 7
  • 49
  • 68
1

I think this post may help you ! Ignore a file for your futur commit and keep this file in your repository

Community
  • 1
  • 1