Git: How to ignore changes to a tracked file?
I have a file with database settings in my project which I have set to some defaults. The file is tracked by Git
and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Git
to ignore new changes to this file?
I tried adding the file to the .gitignore
file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?
git config gitignore
add a comment |
I have a file with database settings in my project which I have set to some defaults. The file is tracked by Git
and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Git
to ignore new changes to this file?
I tried adding the file to the .gitignore
file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?
git config gitignore
1
Read here for one option. You may tell Git to temporarily ignore changes to this file. But in general, it isn't such a good thing to have files which are both treated as versioned and unversioned at the same time.
– Tim Biegeleisen
May 9 '18 at 11:27
1
Possible duplicate of Can I 'git commit' a file and ignore its content changes?
– 1615903
Nov 25 '18 at 15:31
add a comment |
I have a file with database settings in my project which I have set to some defaults. The file is tracked by Git
and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Git
to ignore new changes to this file?
I tried adding the file to the .gitignore
file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?
git config gitignore
I have a file with database settings in my project which I have set to some defaults. The file is tracked by Git
and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Git
to ignore new changes to this file?
I tried adding the file to the .gitignore
file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?
git config gitignore
git config gitignore
asked May 9 '18 at 11:23
Eugen KonkovEugen Konkov
6,31434066
6,31434066
1
Read here for one option. You may tell Git to temporarily ignore changes to this file. But in general, it isn't such a good thing to have files which are both treated as versioned and unversioned at the same time.
– Tim Biegeleisen
May 9 '18 at 11:27
1
Possible duplicate of Can I 'git commit' a file and ignore its content changes?
– 1615903
Nov 25 '18 at 15:31
add a comment |
1
Read here for one option. You may tell Git to temporarily ignore changes to this file. But in general, it isn't such a good thing to have files which are both treated as versioned and unversioned at the same time.
– Tim Biegeleisen
May 9 '18 at 11:27
1
Possible duplicate of Can I 'git commit' a file and ignore its content changes?
– 1615903
Nov 25 '18 at 15:31
1
1
Read here for one option. You may tell Git to temporarily ignore changes to this file. But in general, it isn't such a good thing to have files which are both treated as versioned and unversioned at the same time.
– Tim Biegeleisen
May 9 '18 at 11:27
Read here for one option. You may tell Git to temporarily ignore changes to this file. But in general, it isn't such a good thing to have files which are both treated as versioned and unversioned at the same time.
– Tim Biegeleisen
May 9 '18 at 11:27
1
1
Possible duplicate of Can I 'git commit' a file and ignore its content changes?
– 1615903
Nov 25 '18 at 15:31
Possible duplicate of Can I 'git commit' a file and ignore its content changes?
– 1615903
Nov 25 '18 at 15:31
add a comment |
2 Answers
2
active
oldest
votes
I recommend naming the source-controlled file differently than its actual expected name. For example, if the file is normally named config.json
, then name your example file config.json.dist
and commit this file. Then add config.json
to your .gitignore
file. Your devs would simply cp config.json.dist config.json
after cloning, and then edit it as required, making subsequent commits without having to worry about accidentally changing the default file or forgetting to toggle some setting on and off all the time.
You might even edit your code to search for config.json
first, and if that doesn't exist, fall back to config.json.dist
. This would allow the devs to work without even performing the copy step. (This is how PHPUnit works.)
add a comment |
You can use git update-index --assume-unchanged <file>
And if you want to track it again use git update-index --no-assume-unchanged <file>
1
--assume-unchanged
assumes that a developer shouldn’t change a file.
– Eugen Konkov
May 9 '18 at 11:30
Using this will result in changes still happening to the file but preventing you from switching branches as the file still has changes!
– Alex Ioja-Yang
Sep 18 '18 at 8:44
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50252181%2fgit-how-to-ignore-changes-to-a-tracked-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I recommend naming the source-controlled file differently than its actual expected name. For example, if the file is normally named config.json
, then name your example file config.json.dist
and commit this file. Then add config.json
to your .gitignore
file. Your devs would simply cp config.json.dist config.json
after cloning, and then edit it as required, making subsequent commits without having to worry about accidentally changing the default file or forgetting to toggle some setting on and off all the time.
You might even edit your code to search for config.json
first, and if that doesn't exist, fall back to config.json.dist
. This would allow the devs to work without even performing the copy step. (This is how PHPUnit works.)
add a comment |
I recommend naming the source-controlled file differently than its actual expected name. For example, if the file is normally named config.json
, then name your example file config.json.dist
and commit this file. Then add config.json
to your .gitignore
file. Your devs would simply cp config.json.dist config.json
after cloning, and then edit it as required, making subsequent commits without having to worry about accidentally changing the default file or forgetting to toggle some setting on and off all the time.
You might even edit your code to search for config.json
first, and if that doesn't exist, fall back to config.json.dist
. This would allow the devs to work without even performing the copy step. (This is how PHPUnit works.)
add a comment |
I recommend naming the source-controlled file differently than its actual expected name. For example, if the file is normally named config.json
, then name your example file config.json.dist
and commit this file. Then add config.json
to your .gitignore
file. Your devs would simply cp config.json.dist config.json
after cloning, and then edit it as required, making subsequent commits without having to worry about accidentally changing the default file or forgetting to toggle some setting on and off all the time.
You might even edit your code to search for config.json
first, and if that doesn't exist, fall back to config.json.dist
. This would allow the devs to work without even performing the copy step. (This is how PHPUnit works.)
I recommend naming the source-controlled file differently than its actual expected name. For example, if the file is normally named config.json
, then name your example file config.json.dist
and commit this file. Then add config.json
to your .gitignore
file. Your devs would simply cp config.json.dist config.json
after cloning, and then edit it as required, making subsequent commits without having to worry about accidentally changing the default file or forgetting to toggle some setting on and off all the time.
You might even edit your code to search for config.json
first, and if that doesn't exist, fall back to config.json.dist
. This would allow the devs to work without even performing the copy step. (This is how PHPUnit works.)
edited May 9 '18 at 14:40
answered May 9 '18 at 14:35
Alex HowanskyAlex Howansky
36.7k55684
36.7k55684
add a comment |
add a comment |
You can use git update-index --assume-unchanged <file>
And if you want to track it again use git update-index --no-assume-unchanged <file>
1
--assume-unchanged
assumes that a developer shouldn’t change a file.
– Eugen Konkov
May 9 '18 at 11:30
Using this will result in changes still happening to the file but preventing you from switching branches as the file still has changes!
– Alex Ioja-Yang
Sep 18 '18 at 8:44
add a comment |
You can use git update-index --assume-unchanged <file>
And if you want to track it again use git update-index --no-assume-unchanged <file>
1
--assume-unchanged
assumes that a developer shouldn’t change a file.
– Eugen Konkov
May 9 '18 at 11:30
Using this will result in changes still happening to the file but preventing you from switching branches as the file still has changes!
– Alex Ioja-Yang
Sep 18 '18 at 8:44
add a comment |
You can use git update-index --assume-unchanged <file>
And if you want to track it again use git update-index --no-assume-unchanged <file>
You can use git update-index --assume-unchanged <file>
And if you want to track it again use git update-index --no-assume-unchanged <file>
answered May 9 '18 at 11:27
CorbaCorba
26418
26418
1
--assume-unchanged
assumes that a developer shouldn’t change a file.
– Eugen Konkov
May 9 '18 at 11:30
Using this will result in changes still happening to the file but preventing you from switching branches as the file still has changes!
– Alex Ioja-Yang
Sep 18 '18 at 8:44
add a comment |
1
--assume-unchanged
assumes that a developer shouldn’t change a file.
– Eugen Konkov
May 9 '18 at 11:30
Using this will result in changes still happening to the file but preventing you from switching branches as the file still has changes!
– Alex Ioja-Yang
Sep 18 '18 at 8:44
1
1
--assume-unchanged
assumes that a developer shouldn’t change a file.– Eugen Konkov
May 9 '18 at 11:30
--assume-unchanged
assumes that a developer shouldn’t change a file.– Eugen Konkov
May 9 '18 at 11:30
Using this will result in changes still happening to the file but preventing you from switching branches as the file still has changes!
– Alex Ioja-Yang
Sep 18 '18 at 8:44
Using this will result in changes still happening to the file but preventing you from switching branches as the file still has changes!
– Alex Ioja-Yang
Sep 18 '18 at 8:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50252181%2fgit-how-to-ignore-changes-to-a-tracked-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Read here for one option. You may tell Git to temporarily ignore changes to this file. But in general, it isn't such a good thing to have files which are both treated as versioned and unversioned at the same time.
– Tim Biegeleisen
May 9 '18 at 11:27
1
Possible duplicate of Can I 'git commit' a file and ignore its content changes?
– 1615903
Nov 25 '18 at 15:31