jayeshcp
5/6/2016 - 5:15 PM

Git Snippets

Git Snippets

While on master branch, make a new branch to make new changes:

> git branch --list
* master

> git branch feature1
> git checkout feature1
Switched to branch 'feature1'

> git branch --list
* feature1
  master

Make changes in feature1 branch, and commit it and create patch:

> git format-patch master --stdout > feature1.patch

Now checkout master branch and apply patch:

> git checkout master
Switched to branch 'master'

To check patch stats:

> git apply --stat feature1.patch

To check if patch will apply without any errors:

> git apply --check feature1.patch

To apply patch with sign-off:

> git am --signoff < feature1.patch

To discard changes in working directory:

git checkout -- < file >

To unstage file:

git reset HEAD < file >