Git-bash tweaks

From IronKodiaks Wiki
Jump to navigation Jump to search

Git command shortcuts

Use the instructions below to create git command shortcuts: Eg.: "git br" to be able to use "git branch" or "git ci" instead of "git commit"

  • Create a per-user git config file in your git-bash home directory with the following content:
   #This is git's per-user configuration file.
   #
   [alias]
           co = checkout
           cl = clone
           br = branch
           ci = commit
           st = status
           last = log -l HEAD
  • You can use notepad from the git-bash command line to create the git config file above, like this:
    notepad ~/.gitconfig
  • Once you have saved the file and exited notepad, you can use:
 "git co" instead of "git checkout" and so on - you get the idea.

Visual Diff from git command line

It is very convenient to be able to use a graphical diff tool command in order to be able see code differences, in a visual way as opposed to the built-in text diff tool that git normally provides from the command-line. For example: "git diff <rev1> <rev2>" produces a textual output of the differences between the 2 revisions. It would be nice to be able to instead have the output be sent to a visual diff/merge tool like Meld Follow the instructions in next section

Windows

  • Install Windows version of Meld

It should by default install to C:/Program Files (x86)/Meld/ folder on your Windows machine. The rest of the instructions below assume this default location. If your install location differs, please modify accordingly.

  • Using (Windows) File Explorer (or any other method that you might prefer) copy the file over to the Meld install directory
 Copy C:\Program Files (x86)\Meld\lib\libgirepository-1.0-1.dll --over to -->C:\Program Files (x86)\Meld\
 Note: You may require to assume Admin privileges to be allowed to make the copy
  • Open the same git config file "~/.gitconfig" using Notepad from the git-bash command line. You can use either upper or lower case to spell the name of Notepad (Notepad or notepad) in any combination of case
 notepad ~/.gitconfig
  • Add the following lines to the ~/.gitconfig file from within Notepad
  • In [alias] section, after any existing lines add the "gdiff ..." line below.
  [alias]
      gdiff = difftool --no-symlinks --dir-diff --tool=meld -y
  [merge]
      tool = meld
  [mergetool "meld"]
      path = C:"/Program Files (x86)/Meld/Meld.exe"
      trustExitCode = false
  • Save and exit Notepad (or notepad)
  • Use the following command to try out your new visual diff command
 git gdiff <rev1> <rev2>
  • After a short wait (depending on the speed of your computer and possibly network connection if you are diff-ing a remote file) you should be able see something like the screenshot below
  • You can drill down further to examine any file differences by double-clicking on the .java file you want to examine. See second screenshot below

Visual_Git_Diff_Example


  • Example screenshot of differences in file Climb_Subsystem.java


Visual Diff Example of Climb_Subsystem.java