Friday, November 23, 2012

Git advanced topics

I m going to write features of git which I feel are advanced.

1. Editing a commit which is not HEAD

git rebase -i e39f5d5f122029f6e1271^

where e39f5d5f122029f6e1271 is the commit which I want to amend.

Now some thing like this will come, which is self explanatory,


now change those commits  to "edit" from "pick". Save and close.

Now edit those files you want to and do git add for the files.

After that git commit --amend
then,
git rebase --continue

2. Interactive adding of files(git add -i)


3. Git bisecting to find out where bug was introduced.

commands,

git bisect start
git bisect bad                     /* inform git that current commit you are on is broken */
git bisect good [good_commit_id]                   /* inform git about the working commit */

Now git will checkout to the middle of these commit. You have to build and test if bug exits now.
If bug is present, then type

git bisect bad

else 

git bisect good

To finish,



4.  git add only few changes in same file

    git add -p filename.c

5. Git grep on different branches

git grep -n "string here"


No comments: