custom pages




Jan 2, 2013

Difference between git add . vs git add --all

git add . --- command will index any new files and staging modified files from your working tree to be committed. But it will ignore whatever you have removed files from your working tree.

git add -A/--all -- command will add any new files,modified content, and removed files from your working tree.

Dec 25, 2012

How to view Staged and unstaged files in Git

In Git, Staging means what are the files you have changed those files are added by "git add ." (But not committed into git). simply we can tell "Changes that are staged but not committed".

Similarly in your branch you have changed few files but not yet staged using "git add ."  that means "changes that have not been staged".

git diff - will give you UNSTAGED files list and what are the changes you have done.

git diff -- staged command will give you what are the files and what are the changes on those files that you have staged using "git add" command.

Dec 24, 2012

How to name a stash in Git version control

This article shows the commands related into Git STASH.

git stash - command saves your local changes/uncommitted changes in your local. Stash command is not separate for one branch into other branch that means if you do git stash in master branch and git stash in enhancement(just branch name) branch is not different. If you do "git stash list " it will show all the branches stash list items.

you can see "wip in master,wip in enhancement". so stash is not branch specific.Its common for all branches.

git stash list - It will show you the list of recent stash available in your local git history.

git stash show - It will return recent stash items what are the changed files on the stash.

git stash save - You can give a stash name while you stash.

git stash apply - This command is very useful whenever you want to apply particular or named stash changes in your branch.

git stash apply stash@{3}- If you are planning to apply nth stash you can use for this example i have used for 3rd stash.

git stash show stash@{3}- Similarly you can use show command also. It will list the stashed file details and what are the changes that files had.

git stash drop stash@{3} - if you feel you have applied that 3rd stash no need to maintain hereafter that time you can use drop command. It will delete that stash from your  local git history.

git stash pop - command it will delete your last stored stash because stash generally acts like stack

git stash clear - command it will clear all your stored stash from your local git history.

How to use Regular expression in git stash
git stash save "first stash with description"

if you want to apply the above stash either you need to give the command like git stash apply "first stash with description" or another way is using regular expression like this

git stash apply stash^{/first} - This will apply the youngest stash that matches the regular expression "first". The funny thing is you no need to keep in mind with full stash name.

Nov 27, 2012

How to create a patch in Git Version control

For example, you have master and new feature branches in your remote repository. Always any new enhancement work will be made on new feature branches and once enhancements are done those changes will be merged into master.
Suppose in your new feature branches having 20-30 commits, while merging with master, history will be show all those 20-30 commits and also revert back into our previous commits(suppose some bugs came so that we have to move previous enhancement merge fixes) will be bit headache.

For that better we have to create patch(it will create a single commit, will have all changes) than it will apply to master branch so that going back to previous commits it will be very easy.

* git checkout new_feature
* git diff master >> user_defined_patch_name.patch

It will create a patch file in your current branch, than checkout to master branch than apply.

* git checkout master
* git apply user_defined_patch_name.patch
* git add .
* git commit -m"commit message"
* git push origin master

It will create a single commit in your master repository.

How to checkout other branch particular file in your current branch in GIT

Suppose if you have two branches called "Master" and "test". In some cases if you want to checkout the master branch particular file/files in your test branch. That time the following git checkout command will be very useful.

* Move to your test branch using the following command,

git checkout test
# on test branch do the following command,
git checkout master -- file1.extentsion, file2.extention

The above command will checkout the files from the master branch and override your current branch(in this case "test") file changes.