Reputation: 75
After git clone, to make the code work I have to make some changes locally. So, anytime I have to push code I need to undo those changes before pushing. Is there any way to have some local changes that won't show up in git diff. I don't want to ignore complete files only some part of the code.
Upvotes: 0
Views: 65
Reputation: 301
You could interactively decide wich changes you want to commit. Use git add --patch
to iterate through the chunks of changed code and add what you need. Then you can push those changes and keep the local modifications local.
Upvotes: 1
Reputation: 35135
I suggest splitting the file/code/class into separate files.
Then you have multiple options:
git update-index --assume-unchanged path/to/the/file
git stash
magic with Stash only one file out of multiple files that have changed with Git?Upvotes: 0
Reputation: 30956
Suppose your branch is foo
. Create a new branch bar
from it. Commit the pushable changes in foo
and the non-pushable in bar
.
Whenever you want to test if foo
's code can work, run git rebase foo bar
first, by which bar
will be checked out and updated, and then test the code of updated bar
. If it works, you can push foo
.
If foo
is updated with new commits later, run git rebase foo bar
again to update bar
.
Upvotes: 0
Reputation: 920
Not sure if you can partially ignore a file
You can do an environment variable in a config file that is in the gitignore, then in your code do like
if ENV['some-environment-variable'] == 'some-value'
//do certain things
else if ENV['some-other-environment-variable'] == 'some-other-value'
//do other certain things
else
//do nothing
end
Would that work for your solution?
Upvotes: 1