Git

Alternative to Squash Commit

If we have three commits that we want to squash as below, we can simply use git reset, add and commit to squash those changes into one commit. commit edba792d5ea2aec40f413a23bf539fa25270da65 Author: mdh Date: Thu Feb 27 09:00:16 2020 +1100 Updated model3 commit 8ea10ef480c8cde59b2d78ae0fbe5367f877e59d Author: mdh Date: Thu Feb 27 08:59:51 …

Git

Find a Remote Branch and Fetch it to Local with Git

git branch -r can list all the remote branch. In any large scale application code base, you are likely to get heaps of branch names. By piping grep, we can narrow down the remote branch git branch -r | grep MDH-112 This gives us a fewer options. origin/MDH-112-dev-branch origin/MDH-112-experiment origin/MDH-112-delete …

Git

How to Roll Back Merge Commit on Master Branch with Git

When rolling back a merge commit, I prefer to do it with git revert because it creates a new commit. Using -m 1 indicates that this is a merge and we want to roll back to the parent commit on the master branch. -m 2 is used to specify the …

Git

How to Rename a Branch with Git

Renaming a local branch is easy by using git branch command option -m. For the remote branch, we can create a new remote branch by pushing the renamed branch and then deleting the old branch. Here are the steps. (1) checkout git checkout old-branch-name (2) rename git branch -m new-branch-name …

Git

How to Rebase with Git

Here are the steps to rebase from master with Git. After doing this a few times, rebase is not so scary any more. Rebase vs Merge can be contentious. Generally speaking, I prefer to rebase because it creates a cleaner history. (1) Make sure to be in the feature branch …

Git

Difference Between Git Reset and Revert

Git reset and revert are similar, but understanding the difference is important. They can both roll back the change you made. The differnce is that reset moves the pointer back to the commit you specify, while revert creates another commit at the end of the chain to cancel the change. …

.NET

When To Use FirstOrDefault with Linq Expression

FirstOrDefault is a Linq expression that returns the first element of a sequence or a default value (which is usually null) when no element is found. First is similar, but throws an error when no element is found. FirstOrDefault is usually preferred to First because it does not throw an …

Front-End

What is ‘this’ referencing to in JavaScript?

The JavaScript this keyword refers to all the objects that exist in the function’s call-site. A call-site of a function is the location where the function is called. When a function’s call-site is inside an object, this refers to the object where the function belongs to. When a function’s call-site …