Saturday, October 1, 2016

Git 101.

Basics:
  • help / man 
    • man git
    • man git-log / man git-commit
    • git help log
  • git config --global user.name <your_name>
  • git config --global user.email you@yourdomain.com
  • git config --get remote.origin.ur /home/amy/project
  • git config -l # 
  • git init
  • git status
  • git log (more)
  • git add <filename> (more)
  • git commit -m "message" <filename> (more)
  • git branch <branch_name> (more)
  • git checkout master 
  • git checkout -b <branch_name>
  • git branch (check branch is created)
  • git merge (more)
  • git branch -d <branch-to-delete> # but git ensure the changes is in current branch
  • git branch -D <branch-to-remove> # no changes are reserved
  • git branch -r origin/master # keeps a pristine copy of original branch
  • git revert (more)
  • git clone <directory> <new cloned directory>
    • git commit -a # to commit the new cloned directory in repository
  • ex: git clone amy.org:/home/amy/project  my_repo_directory # ssh protocol
  • git pull <new cloned directory>
    • git fetch <new cloned directory> # to inspect new changes and decide whether to merge
    • git log -p HEAD..FETCH_HEAD
    • gitk HEAD..FETCH_HEAD
    • gitk HEAD...FETCH_HEAD  # show everything reachable from either one but not both
  • git remote add <new directory> <from directory>
    • git fetch <new directory> # inspect without merging
    • git log -p master..new_directory/master # show a list of changes
    • git merge new_directory/master
  • git pull . remotes/new_directory/master # same as above commands, merge without checking
  • git pull # update all changes to local files
  • git push # update files in remote github repository
  • git show <commit number>
  • git show HEAD # tip of current branch
    • git show HEAD^    # parent
    • git show HEAD^^  # grandparent
  • git show experiment1 # tip of experiment1 branch
  • more...
    • git rm [-n][-q][-r] <dir to be removed>
    • git tag v2.5 <your own commit name.
    • git diff v2.5 HEAD
    • git branch new_branch v2.5
    • git reset --hard HEAD^
    • git grep "key_word" v2.5
    • git log v2.5..v2.7
    • git log --since="2 days ago"
    • git log v2.5..  Makefile
    • git log master .. child # commit in child but not master
    • gitk --since="2 days ago"  codec/
    • git diff  v2.5:Makefile  HEAD:Makefile.in
    • git show v2.5:Makefile
  • git docs
  • git tutorial files

EXAMPLE
% tar xzf project.tar.gz
% cd project
% git init
% git add .
% git commit
% git add file1 file2
% git diff --cached
% git status
% git commit -a -m "new changes"
% git log -p
% git log --stat --summary
% git branch experiment1
% git branch
% git checkout experiment1
    ... (edit files)
% git commit -a
% git checkout master
    ... (edit files)
% git commit -a
% git merge experiment1
% git diff
% git commit -a
% (git push to update files in remote github repository)
% git branch -d experiment1
% git branch -D crazy-idea-to-remove

GitHub:
  • git remote add origin https://github.com/myaccount/mynewrepository.git
  • git push -u origin master_branch_name
  • git hash object - use hash code as an identifier for a specific commit
  • git revert <has code number> - to backtrack
  • git pull origin master_branch_name - get most recent changes to local computer

No comments:

Post a Comment