DEV Community

Maciek Chmura
Maciek Chmura

Posted on • Updated on • Originally published at maciek.cloud

How I stay productive in a big project

...and not get lost on the way.

Problem

For almost a year I've been a part of a big and mature JavaScript project. No frameworks. Just Node, JS and MVC. Often times when I am fixing a bug I have to jump into multiple files and classes for investigation. My open files tab gets full really quickly. My main problem is jumping between different solutions for a particular fix.

I want to perform some change in code, test it and leave it for later to go find a different approach. I repeat these steps a few times. Then, when I have a fix that is the best fit, in my opinion, I can make a PR for code review or discuss it with my team.

So ideally I would like to quickly switch between possible fixes.
For this, I have two approaches.

Save a diff file

git diff > fix1.diff

Git will generate a patch file with all the changes made to the repository. I can send this file to someone, open it in its own window to compare with the current state, etc.
Very easy for quick verification.

To apply this file:

git apply fix1.diff

This is the simplest workflow for progressively save your work between commits.
I have just a file with all of the changes.
This is nice and simple, but there are better solutions.

Git Stash

Stashing is saving work for later.
There are many great tutorials and documentation on this topic.
atlassian
git-scm

I found this 2 commands helpful in my case:

git stash save <message>
git stash apply

git stash save will save the changes and clean my working directory, soo to continue working I must apply them back. (git stash pop will also apply changes but they will be deleted from stash).

Now I have a saved point in working "timeline" that I can easily evaluate or revert back to.
This can also be done inside VScode(if you use it) with Gitlens plugin(Webstorm also has this functionality)

** Update
As highlighted by

heberqc image

git stash save is deprecated. Please use git stash push

Micro-tip: personalized comments

I put a comment in this manner:

// @mch <what I think is happening here>

mch > my initials

Within editor, I've set up a rule to highlight @mch string.
For VScode there is nice plugin: TODO

I've customized it with:

"todohighlight.keywords": [
    {
      "text": "TODO",
      "color": "#000000",
      "backgroundColor": "gold",
      "borderRadius": "2px",
    },
    {
      "text": "@mch",
      "color": "#66ffdd",
      "backgroundColor": "#116644",
      "borderRadius": "2px",
    },
  ],

This is helpful to quickly lookup all the places that cought my eye.
Ctrl + Shift + F for them with @mch or use TODO plugin lookup.

These 3 tips help me with day to day work.
What are your hacks for productive work??

Disclaimer:
This post is my first blog'ish publication like ever ever :D
Thank you DEV team for making it possible for me to share :D

Top comments (9)

Collapse
 
hexspeak profile image
Ankur Baranwal

Liked personalized comments. I discourage people from using git stash. It's equally easy to create local branches. Cleaner approach and provides more flexibility in terms of rebasing on top of latest changes after a pull. With that, we can get rid of diff patches as well.

Collapse
 
maciekchmura profile image
Maciek Chmura

Nice tip, thanks :) I will test it with new bug.

Collapse
 
heberqc profile image
Heber Quequejana

Wow, yes or yes I'm going to apply these tips, specially the diff file. I just would like to remember that git stash save is deprecated and now you have to use git stash push instead.
github.com/magit/magit/issues/3349

Collapse
 
maciekchmura profile image
Maciek Chmura

Thank you for the code review :)

Collapse
 
changleetw profile image
Chang Hsin Lee

How do you remember that you have git stashed something if it wasn't immediately used?

Collapse
 
maciekchmura profile image
Maciek Chmura

Inside VSCode, in Gitlens I can see all saved stashes. Inside a single stash entry, I have all modified files. Here I can just click a file to see the diff.

imgur.com/a/apoWEnl

Just by browsing the entries in the stash I can remember what it was about.
Can this be helpful?

Collapse
 
abhinav profile image
Abhinav Kumar • Edited

I do the same thing with # @abhnv:. I also add a colon after my nickname. Otherwise it could mean that it was addressed to me.

Collapse
 
blouzada profile image
Bruno Louzada

Nice recommendations, I will try using got stash and good plugin, thanks for sharing!

Collapse
 
maciekchmura profile image
Maciek Chmura

I'm glad you found it helpful :)