animek sahu
animek sahu

Reputation: 75

Have local non-pushable changes in git

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

Answers (4)

Miguel Berrío
Miguel Berrío

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

tmaj
tmaj

Reputation: 35135

I suggest splitting the file/code/class into separate files.

Then you have multiple options:

  1. git update-index --assume-unchanged path/to/the/file
  2. git stash magic with Stash only one file out of multiple files that have changed with Git?
  3. Add the file with changes you don't want to commit to git ignore.

Upvotes: 0

ElpieKay
ElpieKay

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

MingMan
MingMan

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

Related Questions