Git: How to prevent the transfer of files that have been modified for debugging purposes only?

Many times I would like to change some lines of code to simplify debugging, but I really don't want to commit them. For example, I turn off some annoying features (like ads) by commenting on some lines of code, or I set the levels and log filters only to those who care, or I made the condition be true so that the block of code I want to run works all the time .

In Perforce, I would create a β€œchangelog” for these files and label it β€œNOT COMMITTEE!”. What would be equivalent to this in Git? The branch does not work, because these changes are for debugging only, should exist with the other changes that I am currently doing.

+6
source share
5 answers

Thanks everyone for the answers. What I ended up with was writing a pre-commit hook in git that checks the dont commit line (and other options) in each of the files. If so, then the commit fails, and I will have to edit these lines before committing. This is because the debugging code must be processed separately, and not for each file, since some files have both debugging changes and real changes that need to be performed. (my previous solution with perforce did not address this issue).

0
source

Find the -assume-unchanged option. There is a blog article about this that explains the situation quite well. And also this one , which mentions the search for such ignored files later.

+5
source

What I usually do is just put off the debugging code in my own commit and return it later. A more active solution is to make an intermediate branch from master , call it debug . Make all debug changes to the debug branch, and then release the branch of your debug function. When you are ready to remove the debug changes, simply reinstall your function branch on master .

+1
source

In fact, you do not want to ignore these files, but ignore these changes.

Here I see two solutions:

  • Restore HEAD

The command I use for this situation:

 git checkout -- file ... 

With all the files that you changed for debugging purposes.

This restores the file with HEAD . Then you can safely do your git commit -a or something else.

  1. Tell git to find out what changes to commit (per file)

    git add -p.

See # 1085162 .

But you still need to remove your debugging code.

0
source

One of the solutions that are not universal, but may correspond to some workflow scenarios, is the use of pre-commit Git filters ( manual , manual + samples ). In short, it's just a preprocessing tool that will be called over all committed files before the actual commit. You may have this mechanism for highlighting specific patterns, such as //<NOCOMMIT ... //NOCOMMIT> or whatever. The downside is that these debugging lines may disappear when resetting to commit or even pulling / merging (I have not tested this).

0
source

Source: https://habr.com/ru/post/913586/


All Articles