-1

In preparation for the first day of the fourth month of the year, I've added some, uh "new features", to the development branch of our code.

Upon discovering these features, the first thing my coworkers will do is look at the commit logs to find what changed (and undo it). I could make the changes directly to our deployed code, but then they would be overwritten on the next deployment (which deploys from our development branch).

Is there a way I can commit the code to our development branch without leaving any obvious signs? Or if not, at least making it a little more difficult for my coworkers to find the exact code that was altered?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian H.
  • 2,092
  • 19
  • 39
  • 1
    You can do everything locally without pushing it. Then push it when you want them to know – evolutionxbox Mar 31 '21 at 15:04
  • 8
    One of the main goals of version control systems is to prevent what you're trying to do. Everything commited becomes visible to everyone with access and they can track what changed, when and by whom. – Alejandro Mar 31 '21 at 15:06
  • @evolutionxbox .. that won't work. It is a web app, so in order for them to see it, it will have to be deployed to our development environment, which means either a) it is part of the DEV branch and gets deployed, or b) I make changes directly on the application server, but then they get overwritten during the next build (which happens dozens of times each day) – Brian H. Mar 31 '21 at 15:07
  • 3
    that would, um, defeat the whole purpose of git in the first place. If this is a work environment, I would try to solve this on an organizational level. In other words, solve the issue with your coworkers. And if the issue IS actually your code, solve that. – Dirk Trilsbeek Mar 31 '21 at 15:08
  • 1
    Your intention is to defeat the purpose of having a version control system. git doesn't allow that IMHO. any single commit is your culprit. – Asif Kamran Malick Mar 31 '21 at 15:09
  • 3
    git can't possibly distinguish between your funny goal and a totally malevolent one. – Romain Valeri Mar 31 '21 at 15:16
  • 1
    The best you can do is [change the author info of commit(s)](https://stackoverflow.com/questions/3042437/how-to-change-the-commit-author-for-one-specific-commit). But I'm not sure if that really helps your cause. – Asif Kamran Malick Mar 31 '21 at 15:23
  • 2
    I'm tempted to say that this is the answer to the question: https://workplace.stackexchange.com/a/69494 – legoscia Mar 31 '21 at 15:43
  • 1
    You can rebase the dev branch and add the changes to some commit you already made. Evil. – KamilCuk Mar 31 '21 at 15:44
  • 1
    @KamilCuk - that sounds perfect. What rebase arguments would I use? I'm assuming I would check out and old commit, then make some changes, but not sure how to apply those back to master. – Brian H. Mar 31 '21 at 20:59

1 Answers1

1

that sounds perfect

You can rebase the development branch and add place the changes to some commit you already made. It would be evil, though.

If you do not know how to rebase yet, rebasing is a basic Git operation and you should definitely learn it. My workflow would look like this:

  • Checkout the newest development branch.
  • Edit the files you want to do.
  • Add the changes and create them with some irrelevant commit message, like git commit -m "Rebase me".
  • Find a commit that you made in gitk.
  • Then interactively rebase up until your commit like git rebase -i <commit_sha>^ like git rebase -i 165b520, but you can also git rebase -i --root.
  • Remove your commit line with Rebase me and move the line below your commit (in vim dd removes a line, p pastes the line below current line, P pastes line above current line).
  • Change your commit from pick to fixup (in Vim, place the cursor on beginning of the line and type cwf<esc>).
  • Quit the editor (in Vim, :wq or ZZ).
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
KamilCuk
  • 120,984
  • 8
  • 59
  • 111