Useful git command for developers

Git log

git log --pretty=format:"%h%x09%an%x09%ad%x09%s"

Adding it to the bash script

echo "alias gitl='git log --pretty=format:"%h%x09%an%x09%ad%x09%s"'" >> ~/.bashrc
source ~/.bashrc

From now on you can type:

gitl
3918a7c8        Vivek Bhadra    Wed Oct 23 14:02:16 2019 +0100  Integrating the esp8266 wifi module in SPRESENSE sdk.
cbce5ee6        Vivek Bhadra    Tue Oct 22 13:16:11 2019 +0100  Fixes.
d4fc23c7        Vivek Bhadra    Wed Oct 16 16:01:03 2019 +0100  Enhanced camera App for better user interactivity.
6cc05f93        Vivek Bhadra    Wed Oct 16 13:47:02 2019 +0100  Customized for delayed capture of 1 mins.

and see the formatted git log, change the format as you would like.

Checking your current git branch

git branch -av

Add it to the .bashrc

echo "alias gitb='git branch -av'" >> ~/.bashrc
source ~/.bashrc

Type:

gitb
* customize_for_12_demo             3918a7c8 Integrating the esp8266 wifi module in XYZ sdk.
  master                            ee8f2ddf Merge pull request #41 from XXX/release-v1.4.1
  remotes/origin/HEAD               -> origin/master
  remotes/origin/auto_build_doxygen a5681292 Updated readme and only build doc from master
  remotes/origin/master             ee8f2ddf Merge pull request #41 from XXX/release-v1.4.1
  remotes/origin/release_1.0.1      ec7f3dab Release tag XYZ_1.0.001 YYY.0.001 release.

on the console to check the git branch you are on.

Creating a patch from multiple commits

git format-patch -x --stdout > patch-ddmmyyy.patch
git format-patch --ignore-space-change --ignore-space-at-eol --ignore-all-space -n --stdout > ~/patch4-LH3-18466-19092019.patch

where n is the number of commits you want to get back.
–ignore-space-change
–ignore-space-at-eol
–ignore-all-space
the above options are self-explanatory.

How to remove untracked files in git?

  • Print out the list of files which will be removed (dry run)
git clean -n
  • Delete the untracked files from the repository
git clean -f

How to not display the untracked files with git status?

git status --untracked-files=no

or


git status -uno

Renaming a local branch in command line

switch to the branch you want to rename

git checkout branch-name

Then rename it as below:

git branch -m new-name

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s