Tuesday, June 2, 2015

Basic Git commands

Basic Git commands:
--------------------------

git branch -av -> list all available branches


git branch -D branch_name -> to delete the branch locally


git checkout master -> switch the branch to master


git init - Initialized empty Git repository ...


git add . - add all files


git commit -m 'Initial commit.' - commit the  changes


git checkout -b test - create a new branch test


git branch test  -  Creates test branch  but branch will not be changes to test


git checkout test -  checkout to test and move to test branch


git checkout -f commitid  -> ignore local changes any and revert to commit id specified.


git clean -fd  -> Removing Untracked files


git checkout -f  -> Removing uncommitted tracked files 


Generating patch using git:

-----------------------------------

git format-patch master --stdout  >  fix_empty_poster.patch


=> This will create a new file fix_empty_poster.patch with all changes from the current branch  against master.



git format-patch -1 commit-id    =>  generating the patch using commit id,



Patch commands:

-----------------------

patch -p1 < patch_file -> applying the patch


patch -p1 --dry-run < patch_file -> view how patch is applying . but it will not apply the patch


patch -p1 -R < patch_file - reverting the patch



Applying the patch using git:

-----------------------------
git apply --stat file.patch =>  show stats.

git apply --check file.patch =>  check for error before applying.


git am < file.patch => apply the patch finally.



Git am VS patch command:

-------------------------------------

Patch will just apply code changes and later we need to commit the changes but "Git am" will apply code changes and also commit the patch as it can extract author information. 


Undoing Changes:

--------------------------
git revert <commit>

Generate a new commit that undoes all of the changes introduced in <commit>, then apply it to the current branch.


git reset --hard <commit>

Move the current branch tip backward to <commit> and reset both the staging area and the working directory to match. This obliterates not only the uncommitted changes, but all commits after <commit>, as well.

git clean -f

Remove untracked files from the current directory.

https://www.atlassian.com/git/tutorials/undoing-changes/git-checkout



Debugging with GIT:

---------------------------

Git bisect  - The bisect command does a binary search through your commit history to help you identify as quickly as possible which commit introduced an issue.


Git blame - you can annotate the file with git blame to see when each line of the method was last edited and by whom.


https://git-scm.com/book/en/v2/Git-Tools-Debugging-with-Git



To know the URL of the local GIT repositery:           git remote show origin

Basic Git commands

Basic Git commands:
--------------------------

git branch -av -> list all available branches


git branch -D branch_name -> to delete the branch locally


git checkout master -> switch the branch to master


git init - Initialized empty Git repository ...


git add . - add all files


git commit -m 'Initial commit.' - commit the  changes


git checkout -b test - create a new branch test


git branch test  -  Creates test branch  but branch will not be changes to test


git checkout test -  checkout to test and move to test branch


git checkout -f commitid  -> ignore local changes any and revert to commit id specified.


git clean -fd  -> Removing Untracked files


git checkout -f  -> Removing uncommitted tracked files 


Generating patch using git:

-----------------------------------

git format-patch master --stdout  >  fix_empty_poster.patch


=> This will create a new file fix_empty_poster.patch with all changes from the current branch  against master.



git format-patch -1 commit-id    =>  generating the patch using commit id,



Patch commands:

-----------------------

patch -p1 < patch_file -> applying the patch


patch -p1 --dry-run < patch_file -> view how patch is applying . but it will not apply the patch


patch -p1 -R < patch_file - reverting the patch



Applying the patch using git:

-----------------------------
git apply --stat file.patch =>  show stats.

git apply --check file.patch =>  check for error before applying.


git am < file.patch => apply the patch finally.



Git am VS patch command:

-------------------------------------

Patch will just apply code changes and later we need to commit the changes but "Git am" will apply code changes and also commit the patch as it can extract author information. 


Undoing Changes:

--------------------------
git revert <commit>

Generate a new commit that undoes all of the changes introduced in <commit>, then apply it to the current branch.


git reset --hard <commit>

Move the current branch tip backward to <commit> and reset both the staging area and the working directory to match. This obliterates not only the uncommitted changes, but all commits after <commit>, as well.

git clean -f

Remove untracked files from the current directory.

https://www.atlassian.com/git/tutorials/undoing-changes/git-checkout



Debugging with GIT:

---------------------------

Git bisect  - The bisect command does a binary search through your commit history to help you identify as quickly as possible which commit introduced an issue.


Git blame - you can annotate the file with git blame to see when each line of the method was last edited and by whom.


https://git-scm.com/book/en/v2/Git-Tools-Debugging-with-Git



To know the URL of the local GIT repositery:           git remote show origin