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?
3 Answers
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.

- 68,258
- 9
- 99
- 134
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

- 13,354
- 7
- 49
- 68
I think this post may help you ! Ignore a file for your futur commit and keep this file in your repository

- 1
- 1

- 13
- 4