Archive for the ‘Javascript Programming’ Category

Amending and Squashing Commits in Git   no comments

Posted at 7:17 am in Javascript Programming

Have you ever committed code to your Git repository, and then realized that you forgot something or there was an error in your code? Wish there was an easy way to amend your commit with the fix? What about if you’ve already pushed your code or made several commits?

If you run a strong test suite, and commit before running the whole test, this probably happens regularly (at least it does for me). Usually each fix you make will require a separate commit until the test suite passes. While there is nothing wrong with many small commits, sometimes it is helpful to squash many commits into one complete commit, especially when hooking project management software into your Git commits. This article discusses a technique used to squash multiple commits in branch (even master) into a single commit. Next week we will discuss another approach to this problem where you start in a branch and squash when you merge the branch into master.

Getting ready

You will need Git install on your machine and GitX is also useful for visualizing the Git commit tree.

How to do it…

In the simplest situation, where you have just committed and now need to amend that commit:

git add .
git commit --amend

If you have 2 or more previous commits that you want to squash, then read on. The follow steps discuss how to squash multiple commits.

The following command will list the previous commit(s) (change -1 to -N, where N is the number of previous commits to see). However, it is much easier to see commit using a tool like GitX.

git log -1 --sparse

Running the previous command will output something like:

commit a8e3d75acc974a76bc7aafb43b392a69ab1bab57
Author: Matthew Snider 
Date:   Thu Jan 19 14:05:55 2012 -0800

    [#23700817] COMMIT MESSAGE B

commit 7c44b35795b03426861963ad8cc9f5bd1898d901
Author: Matthew Snider 
Date:   Thu Jan 19 14:44:01 2012 -0800

    [#23700817] COMMIT MESSAGE A

Grab the SHA-1 of your latest commit (we’ll call this B, a8e3d75acc974a76bc7aafb43b392a69ab1bab57), and the SHA-1 of the previous commit that you want to squash into (we’ll call this A, 7c44b35795b03426861963ad8cc9f5bd1898d901). It doesn’t have to be the immediately previous commit, if you want to squash several commits together, but I usually only squash 2 commits together for sanity reasons.

Move the Git back to the lastest commit (B) that we want to squash (detached HEAD, you are in a temp mode now and won’t affect master):

git checkout 

Reset the branch pointer to the initial commit (A), but leave the index and working tree intact:

git reset --soft 

Amend the commit (A) on the initial tree using the tree from ‘B’:

git commit --amend

Get the SHA-1 of the current commit (we’ll call this commit C):

git rev-parse HEAD

Go back to the original branch (we assumed master for this example, but this can be done just as easily on a branch as well):

git checkout master

Replay all the commits after B onto the new initial commit:

git rebase --onto  

Push changes to master:

git push origin master

How it works…

The simple solution simply adjustes the previous commit tree to include your most recent changes that you added. It also gives you an opportunity to update the commit message. If you have not added new changes, then the amend command will simply allow you to change your previous commits message.

If you are changing more than the previous commit, these steps cause Git to jump to a forward commit, then move back to a previous commit, without actually updating the tree. Since the changes from the forward commit are still there, you can amend them onto the previous commit, creating a new updated commit containing the first commit and all changes until the forward commit. Once you push to master it will be as if the there was ever only 1 commit.

There’s more…

This technique was originally found on the Stack Overflow article git-how-to-squash-the-first-two-commits. The author follows similar steps to those above, but instead of remembering the newly created commit SHA, he tags the commit for referencing and deletes the tag at the end. The questioner was trying to squash their first and second commits ever in master, so this technique can be used to cleanup any part of your Git history. Additionally, if you replace master in the steps above with whatever active branch you are using, then you can use this same techique on your branches.

Written by Admin on January 28th, 2012

Tagged with , ,

Web Development News Week 3, January 2012   no comments

Posted at 12:10 am in Javascript Programming

Web development news for the 3rd week of 2012:

JavaScript

JavaScript Weekly, Issue #62 – January 20th, 2012

The V8 Myth: Why JavaScript is not a Worthy Competitor, JavaScript Design Patterns: Decorators, Simplicity and JavaScript Modules, …

HTML 5

HTML 5 Weekly, Issue #21 – January 18th, 2011

(Better) Tabs with Round Out Borders using CSS3, The Lowdown on :Before and :After in CSS, The CSS3 Click Chart, …

Browsers

Christian Heilmann wrote an interesting article about some real world browser stats.

Written by Admin on January 25th, 2012

Tagged with , , , ,

Web Development News Week 2, January 2012   no comments

Posted at 9:10 pm in Javascript Programming

Web development news for the 2nd week of 2012:

JavaScript

JavaScript Weekly, Issue #61 – January 13th, 2012

What You May Not Know About jQuery (in 5 Methods), JavaScript’s ‘eval’ Considered Crazy, Writing Quality Third-Party JS: Part 1 – The First Rule, …

HTML 5

HTML 5 Weekly, Issue #20 – January 11th, 2011

Profiling CSS for fun and profit. Optimization notes, 7 Things Still Missing From CSS, Cut the Rope: A Slick HTML5 Game from Microsoft and ZeptoLab, …

Written by Admin on January 18th, 2012

Tagged with , , , ,

Web Development News Week 1, January 2012   no comments

Posted at 5:33 am in Javascript Programming

Web development news for the 1st week of 2012:

JavaScript

JavaScript Weekly, Issue #60 – January 6th, 2012

WebStorm 3.0: A JavaScript IDE from JetBrains, JsFiddle Tips And Tricks, Matador: An MVC Framework for Node (by Dustin Diaz), …

HTML 5

HTML 5 Weekly, Issue #19 – January 4th, 2011

Foundation HTML5 Animation with JavaScript, How Google Ported ‘Angry Birds’ to HTML5, Implementing Minecraft in WebGL, …

Written by Admin on January 13th, 2012

Tagged with , , , ,

Web Development News Week 51 – 52, December 2011   no comments

Posted at 3:16 pm in Javascript Programming

Sorry to miss my update last week, I was spending time with the family and wasn’t able to post. However, 2012 is here and I hope find time to write more substantive articles.

Anyway here is the web development news for the last two weeks of 2011:

JavaScript

JavaScript Weekly, Issue #58 – December 23rd, 2011

Fake Operator Overloading in JavaScript, JavaScript as a First Language class, Your jQuery: Now With 67% Less Suck, …

JavaScript Weekly, Issue #59 – December 30th, 2011

The Rise and Rise of JavaScript, The JS Guide to Objects, Functions, Closures and Scope, 12 Days of CreativeJS, …

HTML 5

HTML 5 Weekly, Issue #18 – December 21st, 2011

The Smallest Possible Valid (X)HTML Documents, The HTML5 ‘output’ Element, Internet Explorer to Get Automatic Upgrades across XP, Vista and Windows 7, …

Written by Admin on January 6th, 2012

Tagged with , , , ,

Web Development News Week 50, December 2011   no comments

Posted at 2:51 pm in Javascript Programming

Web development news for the 50th week of 2011:

JavaScript

JavaScript Weekly, Issue #57 – December 16th, 2011

SOLID JavaScript: The Single Responsibility Principle, A Case Against Using CoffeeScript, JSPkg: A New Place to Host JavaScript Packages, …

PPK discusses the state of static positioning in mobile browsers: Position Fixed.

Nicholas Zakas discusses timer resolution in browsers. He’s discussed this topic before, but is updating us on the present and future of timer resolution.

HTML 5

HTML 5 Weekly, Issue #17 – December 14th, 2011

How to Use Firebug on your iPad and iPhone, HTML5 Scorecard: Amazon Kindle Fire, What I Learned About the Web in 2011: An Experts’ Roundup, …

Written by Admin on December 21st, 2011

Tagged with , , , ,

Web Development News Week 49, December 2011   no comments

Posted at 6:59 pm in Javascript Programming

Web development news for the 49th week of 2011:

JavaScript

JavaScript Weekly, Issue #56 – December 9nd, 2011

What is Happening to the jQuery Plugins Site, Introducing ECMAScript 5.1, Introducing Mozilla’s JavaScript Native File Management: OS.File, …

It’s time again for the yearly JavaScript Developer Survery.

HTML 5

HTML 5 Weekly, Issue #16 – December 7th, 2011

Top 6 Trends In HTML5 In 2011, Auto-Saving User Input In Your Forms With HTML5 and Sisyphus.js, Let’s have a look at some recently landed Web APIs for Firefox, …

Python

I discovered an interesting article on the Yipit blog, where they discuss feature flipping in a continuous deployment Django/Python environment: Getting to Continuous Deployment in Django: Feature Flipping.

Written by Admin on December 18th, 2011

Tagged with , , , ,

Web Development News Week 48, December 2011   no comments

Posted at 11:38 am in Javascript Programming

Web development news for the 48th week of 2011:

JavaScript

JavaScript Weekly, Issue #55 – December 2nd, 2011

JavaScript Libraries Now Used by 50% of Top 1m Web Sites, Principles of Writing Consistent Idiomatic JavaScript, Nondeterministic Turing Machine Simulator in 23 Lines of JavaScript, …

I also found Extending JavaScript Natives by Angus Croll very interesting. It covers a lot of the reasons why we all know not to extend natives in JavaScript, but also mentions a few cases where it might make sense to bend this rule.

HTML 5

HTML 5 Weekly, Issue #15 – November 30th, 2011

Stitches – An HTML5 Sprite Generator, Typography Effects with CSS3 and jQuery, HTML5 Semantics and Good Coding Practices, …

Written by Admin on December 7th, 2011

Tagged with , , , ,

Web Development News Week 47, November 2011   no comments

Posted at 10:48 pm in Javascript Programming

Web development news for the 47th week of 2011:

JavaScript

JavaScript Weekly, Issue #54 – November 25th, 2011

Felix’s Node.js Style Guide, Face Detection jQuery Plugin, Asynchronous UIs – The Future of Web User Interfaces, …

HTML 5

HTML 5 Weekly, Issue #14 – November 23rd, 2011

Adobe Donates Flex to Apache, The Fundamentals, Primitives and History of HTML5, Going Fullscreen with Canvas, …

CSS

If you aren’t using SASS to better manage your CSS, then you should check out this article, Getting Started With SASS from A List Apart. I’ve started using SASS for all my projects as it allows for easier cross-browser support and I have to write much less code.

General

Many web companies are opposing SOPA, the A List Apart article, Say No to SOPA, describes why you should oppose SOPA as well.

Written by Admin on November 29th, 2011

Tagged with , , , ,

Web Development News Week 38, September 2011   no comments

Posted at 1:32 am in Javascript Programming

Web development news for the 38th week of 2011:

JavaScript

JavaScript Weekly, Issue #45 – September 23, 2011

V8 the technology behind Node.js has fixed a 1gb memory limit, learning JavaScript articles, faster performance with memoization, namespacing patterns, …

YUI has released version 3.4.1.

HTML 5

HTML 5 Weekly, Issue #5 – September 21, 2011

Written by Admin on November 28th, 2011

Tagged with , , , ,