Monday, October 26, 2015

vimdiff tool usage notes

vimdiff Keyboard Shortcuts:

do - Get changes from other window into the current window.

dp - Put the changes from current window into the other window.

]c - Jump to the next change.

[c - Jump to the previous change.

Ctrl W + Ctrl W - Switch to the other split window.

:qa to quit all
:qa! to quit all without saving
:wqa save and quit all

Note: 
  • If you load up two files in splits (:vs or :sp), you can do :diffthis on each window and achieve a diff of files that were already loaded in buffers
  • :diffoff can be used to turn off the diff mode. 

Link: http://amjith.blogspot.in/2008/08/quick-and-dirty-vimdiff-tutorial.html  

Sunday, October 25, 2015

Google Repo command


Google Repo Command tips:

Intro: The Google repo command used to manage multiple git repository under single umberlla.


To list status for all git repo
repo forall -c 'git status'

To lists status for all with repo name git repository under manifest
repo forall -c 'pwd; git status'
repo forall -c 'pwd; git status -s| cut -c4- '

To pull all the repo changes
repo forall -c 'git reset --hard'
repo forall -c 'git clean -fd'
repo sync && repo start --all



Friday, October 16, 2015

Git commands


Basics:
========
To add files to be committed      
  git add 
To commit a change in the local tree. To be done after the git add.
  git commit -m "comment about the changes"
To push the changes or checkin the changes to main branch    
  git push
To discard all changes done in a branch locally
  git stash save --keep-index
  git stash drop
    
To create a new branch     
  git checkout -b myBranch
 
To create a patch from the local branch
 Before this check out a new branch, do all changes in the branch, verify it. And then commit those changes. Do not push the changes to master.
 git format-patch master --stdout > myPatch.patch

git reset  updates the index for that path so that it matches HEAD (the current commit). 
It doesn't touch the working tree

git rm --cached -r  to remove a directory which was added.
 
GT Diff:
==========
git diff HEAD@{1}
The @{1} means "the previous position of the ref I've specified", so that
evaluates to what you had checked out previously - just before the pull.

git diff HEAD@{1} filename
This is a general thing - if you want to know about the state of a file
in a given commit, you specify the commit and the file, not an ID/hash
specific to the file.

git diff --cached --name-only   
It lists the filenames in the staging area that will be committed to git. Can be used after all the files to be committed are added thru 'git add'  to verify only intended files are being commited

git difftool --cached
the diff of files that are about to be committed against the head will be showed in vimdiff one by one.

git difftool  
the diff of files in the two commits will be shown in vimdiff one by one.

git log --pretty=oneline
compact display of git log

how about 
  • git diff --name-only for changes relative to index
  • git diff --name-only --staged for ... well staged chages :)
  • git diff --name-only HEAD got both
To get the modified files alone:
git status --porcelain|awk '{if($1=="M") {print "basename " $2}}'|sh

To copy the modified files alone to a remote server, as below:
git status --porcelain|awk '{if($1=="M") {print "scp " $2 " account_name@server_ip:~/my_codebase/$(dirname " $2 ")/;"} }'|sh


Global GIT Configuration: ~/.gitconfig

#vi ~/.gitconfig
[alias]
    st = status
    ci = commit
    br = branch
    co = checkout
    df = diff
    dc = diff --cached
    lg = log -p
    who = shortlog -s --
    changes=diff --name-status -r
    diffstat=diff --stat -r
    logtree = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
    last = log -1 HEAD
    tree = log --graph --decorate --pretty=oneline --abbrev-commit
     # format %cd with --date=short cuts the timezone in log 
    ll = log --graph --pretty=format:\"%C(yellow)%h %C(green)(%cd)%C(auto)%d %Creset%s [%an]\" --date=short
    logtree = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
 
[user]
        email = emailid@email.com
        name = Name S
[color]
        ui = auto
[diff]
        tool = vimdiff



# run
git config --global diff.tool vimdiff  #to defibe difftool
git difftool    # launch vimdiff with changes

This will add alias "tree"
git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit"

For external file diff usage
[diff]
    external = /bin/git-meld.sh


$ cat /home/<dir>/bin/git-meld.sh
#!/bin/bash

meld $2 $5





vi editor ~/.vimrc



" Run time config for vim editor
set cindent    " for c indentation(correct spacing)
syntax on    "To color the VIM editor
set nu ” line numbers
set ts=4 " –> for tab spaces set to four per tab character
set sw=4 "–> Set the shift width to four spaces
set spell " –> set spellchecking on
 set spl=en "–> Set spelling language to english
set ai "–> Enable auto indentation
set nu "–> Enables line numbers
" To remember last position of open file
if has("autocmd")
  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

endif