Git

Created Thursday 28 November 2013

  1. Site:
    1. http://git-scm.com/
  2. Book:
    1. http://git-scm.com/book
  3. Git-flow:
    1. http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/

  1. Reset changes to previous commit:
    1. http://stackoverflow.com/questions/4114095/revert-to-previous-git-commit
      1. git reset --hard <commitName> - follow the link for more options
  2. List all tracked files:
    1. http://stackoverflow.com/questions/8533202/list-files-in-local-git-repo
      1. git ls-tree --full-tree -r HEAD
    2. git ls-tree --full-tree -r HEAD | awk '{print $4}'
  3. Set identity and editor:
    1. http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup
      1. git config --global user.name "Your Name"
      2. **git config --global user.email your@email.com**
      3. git config --global core.editor vi
  4. Add files according to paths list taken from other repository:
    1. Making the list:
      1. git ls-tree --full-tree -r HEAD | awk '{print $4}' > trackedFilesList.txt
      2. touch addFiles.sh
      3. emacs addFiles.sh
      4. http://www.thegeekstuff.com/2010/07/bash-string-manipulation/
      5. http://linux.about.com/od/Bash_Scripting_Solutions/a/How-To-Pass-Arguments-To-A-Bash-Script.htm
      6. The script:
#!/bin/bash
# Global vars
trackedFilesListPath=$1 # Run ./addScript.sh path/to/filesList.txt
rootDirPath=$2 # Run ./addScript.sh path/to/filesList.txt /path/to/root WITHOUT trailing "/"

# Checking/setting the root path
if [ ! -d $rootDirPath ]; then
echo "$rootDirPath is not a directory!"; exit 1
elif [ -z $rootDirPath ] || [ $rootDirPath == "." ]; then
rootDirPath=$(pwd)
echo "HELLO $rootDirPath"
fi

# Parsing the list
if [ ! -f $trackedFilesListPath ]; then
echo "no path to files list is found!"
elif [ -z $trackedFilesListPath ]; then
echo "don't forget feed the script! (Path to files list is required)"
else
while read line; do
fullFilePath="$rootDirPath/$line"
fullFilePath=`echo "$fullFilePath" | sed 's/pattern-1/replacement-1/g'`
fullFilePath=`echo "$fullFilePath" | sed 's/pattern-2/replacement-2/g'`
fullFilePath=`echo "$fullFilePath" | sed 's/pattern-3/replacement-3/g'`

if [ ! -f $fullFilePath ]; then
echo "doesn't exist-> $fullFilePath"
else
(cd $rootDirPath && git add $fullFilePath)
fi
done < $trackedFilesListPath
fi
  1. Untrack files:
    1. http://aralbalkan.com/2389/
    2. http://source.kohlerville.com/2009/02/untrack-files-in-git/
      1. git rm --cached filename
  2. View reflog with file names:
    1. http://git-scm.com/docs/git-reflog
    2. http://stackoverflow.com/questions/1230084/how-to-have-git-log-show-filenames-like-svn-log-v
    3. git reflog show --name-only
    4. git reflog show --name-status
  3. View the list of branches ordered by freshiest
    1. http://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
    2. git for-each-ref --sort=-committerdate refs/heads/
  4. List/change global user params
    1. http://alvinalexander.com/git/git-show-change-username-email-address
    2. vi ~/.gitconfig
  5. Ignore directory except some subdirectory
    1. http://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder
# you can skip this first one if it is not already excluded by prior patterns
!application/

application/*
!application/language/

application/language/*
!application/language/gr/
http://git-scm.com/docs/gitignore
  1. Check gitignore
    1. http://git-scm.com/docs/git-check-ignore
'git check-ignore' [options] pathname...
'git check-ignore' [options] --stdin < <list-of-paths>



Backlinks: