How do you save code that does NOT work?

During development, I sometimes try to use a technique or method that is not immediately disclosed. As soon as I decide to move to another task or try a different method for the same task, I’m never sure what to do with non-working code. I want to save it as a record of what I tried, so I know it doesn't work, or even as a starting point for trying to get it to work again.

Usually I just leave the code in place, commented out and not connected to VCS for some time. However, this becomes a pain as it clutters the code and must be avoided by VCS commits. I use git, which has a "stash" function for temporary storage, but I'm not sure if this is a suitable use.

How do you handle the code that you want to keep for posterity but don’t want as part of your main code base?

+6
source share
3 answers

Branches!

  • Use branches liberally (jQuery_slider_nivo, jQuery_slider_zurb, etc.)
  • You are right that stash has no place to store this code for a long time.
  • If you want to check the code, just switch to this thread
  • If you want this to just merge branches

You can also perform archive operations ($ = console):

  • Archive: $ git checkout -b archive / <branchname> <branchname>
  • Delete it: $ git branch -d <branchname>
  • Restore it: $ git checkout -b <branchname> archive / <branchname>

where <branchname> == TotallyAwesomeBranchName

... or whatever you call your branches =]

+9
source

Each time you run a "task", create a branch. You can later save everything that you tried in this thread and fix the working code for management.

+5
source

You may have created a separate thread for your function, for example feature/doSomethingCool . Now you can move this (not very cool) branch out of your way as

 git branch -m feature/doSomethingCool archive/doSomethingCool-try1 

and create a new feature/doSomethingCool from develop . With archive/doSomethingCool-try1 -branch, you can do what you want, even ignoring or deleting.

+1
source

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


All Articles