Git

https://www.atlassian.com/git/tutorials

Getting Started

Undoing Changes

Undo latest commit using git revert HEAD ``` ~/code/gitfaffing % git log --oneline 481db44 (HEAD -> master) crazy edit of world.txt be880c6 added world.txt and edited hello.txt aa1a9d2 init ~/code/...

Branch

list branches git branch ` create (and checkout) new branch git checkout -b crazy-experiment ` delete branch (after merging) git branch -d crazy-experiment delete branch (not merged but you don...

Convert local master into a branch

If you want to convert a local master branch (that is ahead of remote) into a branch bash git checkout master git branch experiment git reset --hard heroku/master git checkout experiment

  • Updated 14 days ago by vince
Rebase experimental branches

Fake everyone (including yourself) by squashing stupid commits on your experimental branch and then merging a pristine commit to master git checkout -b crazy-experiment do lots of stupid commits ...

Checkout one from from a previous commit

git checkout c96a579 app/assets/stylesheets/menu.scss

  • Updated about 2 months ago by vince
Branch from a previous commit on master as though the branch was made before ...

remove the commits from master as though you had made the branch before those commits were made git checkout master git branch branch-name git reset --hard <sha1>

  • Updated 2 months ago by vince
Git stash

takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them git stash -u git checkout master git checkout crazy-experiment git stash pop stash ...

Change (Amend) commit message

if you just made a commit and want to change the message git commit --amend -m "better commit message"

  • Updated 2 months ago by vince
Merge

Fast Forward Merge when you just have a simple branch from the master tip ``` Start a new feature git checkout -b new-feature master Edit some files git add <file> git commit -m "Start a feature" E...

Tips and Tricks

see compact tree of all your commits git log --graph --all --oneline --decorate if you do this a lot, you can add it as an alias ~/gitfaffing % git config --global alias.go 'log --graph --all --...

  • Updated 3 months ago by vince
Working Directory, Staging Area, and Repository

(a) The working directory contains the files that are not handled by git. These files are also referred to as "untracked files." (b) Staging area contains the files that are going to be a part of t...