Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Engineering Concepts (http://www.go4expert.com/articles/engineering-concepts-tutorials/)
-   -   Git Tips and Tricks (http://www.go4expert.com/articles/git-tips-tricks-t29313/)

pradeep 28Nov2012 22:40

Git Tips and Tricks
 
I have tried introducing people to Git VCS, both personally and through by articles at G4E, I have written 2 articles, Introduction to Git VCS & Git VCS - Cloning & Workflow, in this article

Get A List Of Files Modified Between Two Commits



At times working on a feature or an enhancement of an already live project we might forget some files which we might have worked on, or we might need to make the feature live, and so we need to know the files to make live. With this command you can get the list of file between two commit.

Code:

git diff --name-only SHA1 SHA2


Example:
Code:

pradeep@deepz-desktop:~/Desktop/Programs/utils$ git diff --name-only fbf08d 001b
config.pl
sparse.pl
ssl.db



Ignoring Some Files



There are some files which we might not want to use version control on, like logs, temporary files, binary files like images etc. But they always show up on git status command. For this purpose git reads a special file .gitignore where you can specify the files/directories, by names and/or wildcards the items you want to be ignored by Git. See the example below.

Code:

pradeep@deepz-desktop:~/Desktop/Programs/utils$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   config.pl
#   modified:   sparse.pl
#   modified:   ssl.db
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   config.pl~
#   sparse.pl~
no changes added to commit (use "git add" and/or "git commit -a")
pradeep@deepz-desktop:~/Desktop/Programs/utils$ vim .gitignore
pradeep@deepz-desktop:~/Desktop/Programs/utils$ cat .gitignore
*.bak
*.tgz
*.gz
*~
pradeep@deepz-desktop:~/Desktop/Programs/utils$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .gitignore
#   modified:   config.pl
#   modified:   sparse.pl
#   modified:   ssl.db
#
no changes added to commit (use "git add" and/or "git commit -a")


As you can see from the example, the untracked files ending with ~ are no more reported by Git.

Creating Git Aliases



Like all command-line statements we might also like to shorten frequently used Git command like commit branch etc. You can set them up easily, all you have to do is to edit the .gitconfig file and add aliases under the [alias] section, checkout the example below.

Code:

[alias]
ci = commit
co = checkout
up = pull origin master


Now, you can issue commands like this,

Code:

pradeep@deepz-desktop:~/Desktop/Programs/utils$ git ci -m 'My commit'



All times are GMT +5.5. The time now is 19:42.