Pages

Tuesday, December 11, 2012

GIT Commands

Setting up the environment :

Configuration files exist in three places :

(Windows)

System (all users of the same machine) wide, typically located in
  • C:\Program Files\git\etc\gitconfig
  • Configuration command: git config --system
User specific (Global), typically located in :
  • C:\users\*user*\.gitconfig
  • Configuration command:  git config --global
Project specific, located in :
  • Working project directory ie: C:\development\.git\config
  • Configuration command: git config
Modifying specific configuration files via the command line :

As a brief run through, we'll focus on manipulating a user specific configuration file (global configuration) to outline some of the rudimentary configuration steps.

git-bash> git config --global user.name "W Wright"
git-bash> git config --global user.email ""wemail@dne.com"" (single quotes)
git-bash> git config --global core.editor "notepad.exe" (Google for neat configurations for this)
git-bash> git config --global color.ui true
git-bash> git config --list
git-bash> git init
git-bash> git add .
git-bash> git add <filename>
git-bash> git status
git-bash> git rm <filename>  *permanent, unix like rm*
git-bash> git mv <filename> <filename>
git-bash> git diff
git-bash> git diff <filename>
git-bash> git checkout <branch name>
git-bash> git checkout -- <filename/folder>
git-bash> git commit --ammend -m "message" * ammends changes to HEAD pointer commit*
git-bash> git log
git-bash> git checkout <10-30 numbers from SHA-1> -- <filename> *checkout from a revision puts it into staging tree*
git-bash> git diff --staged
git-bash> git reset HEAD <filename> *removes an item from the staging tree*
git-bash> git revert <10-30 characters from SHA-1> * complete mirror reversal of commit, done using the last HEAD pointer commit value*

Undoing multiple commits *dangerous*


git-bash> git reset --soft <SHA-1 to reset to>
  • resets the version in the repository, does not affect the updated versions contained in either the staging index or the working directory. diff will show all the differences between the files in repo versus working/staging dir.
 git-bash> git reset --mixed (default) <SHA-1 to reset to>
  • moves head pointer to specified commit, also changes staging index, but does not affect the working directory.  
 git-bash> git reset --hard <SHA-1 to reset to>
  • moves pointer of repository but also makes staging and working directory match the affects of the reset.  (All updated files in the staging & working) will be changed.
--------------------
git-bash> git clean -n (test run for removing untracked files contained in working directory)
git-bash> git clean -f (removes untracked files contained in working directory)

.gitgnore file - to avoid git from complaining about untracked specific file types, etc.

git-bash> git config --global core.excludesfile ~/.gitignore (Global ignore file - specify location)

git-bash>  git rm --cached <filename>  to remove a file from the staging index after ignoring it.  (a method to ignore already tracked files)






No comments:

Post a Comment