0

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.

  • You can't partially ignore a file. You can, however, only _add_ parts of the file. – jhpratt Aug 21 '18 at 02:58
  • What *kind* of changes? There are good ways to handle most scenarios but no good way to handle broken processes, please elaborate on what kind of changes you have to do to make the code work locally. – Lasse V. Karlsen Aug 21 '18 at 12:23

4 Answers4

1

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?

MingMan
  • 1,069
  • 1
  • 10
  • 28
1

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.

Miguel Berrío
  • 301
  • 1
  • 7
  • I want to have some permanent local changes in the code. So, I don't have to choose changes to push every time. @ElpieKay 's solution works for that. Thanks for the response. – animek sahu Aug 25 '18 at 00:21
0

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.

ElpieKay
  • 19,185
  • 5
  • 22
  • 36
0

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.
tymtam
  • 20,472
  • 3
  • 58
  • 92
  • I can't change the structure used by the master project. So, this doesn't work for me. Thanks for the response. – animek sahu Aug 25 '18 at 00:23