On Github szeller / git_101
* However, GitHub is the reason we are all using git today
git log -2 -w -p origin/master^Install git-up - https://github.com/aanand/git-up Learn how to set up aliases in your ~/.gitconfig
In general, everything that you use to refer to an object (checkin/branch/tag/etc) in git is a reference into the giant tree of commits. Some implications of this:
* ff2f4cd | (HEAD, foo) checkin some even better stuff (2 minutes ago) (Shawn Zeller) * 4ba0f66 | checkin some great stuff (2 minutes ago) (Shawn Zeller) * 337330e | (origin/develop, develop) restore /registry since that seems to be what we use for the health check (4 days ago) (Shawn Zeller) * d778846 | merge autoZK to dev (8 days ago) (austin chau) |\ | * a205cc4 | use latest debian plugin (8 days ago) (austin chau)337330e HEAD^^ HEAD~2 develop origin/develop 337330e3c25f6c615f0365cc592ed6f0a815fbf1 ... all the same commit
git diff -w cd78ce87e1a HEAD main.coffee
git branch a/cool/branch/name cd78ce87e1a
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch *.deb' --prune-empty --tag-name-filter cat -- --all
git filter-branch --prune-empty --subdirectory-filter some_cool_folder master
git push heroku master
History of shared working brances should be treated as immutable once your commits have been shared. Feature/working branches allow for:
Making sure that you don't accidentally break the build Storing incremental work on github so that you can more easily show it to someone else Making as many incremental commits as you want Cleaning up your commit history later In general, all work should be on a branch
* ff2f4cd | (HEAD, foo) checkin some even better stuff (2 minutes ago) (Shawn Zeller) * 4ba0f66 | checkin some great stuff (2 minutes ago) (Shawn Zeller) * 337330e | (origin/develop, develop) restore /registry since that seems to be what we use for the health check (4 days ago) (Shawn Zeller)
git reset --hard HEAD^
git reset HEAD^
git reset develop git add . git commit -m "all my stuff"
* 337330e | (origin/develop, develop) restore /registry since that seems to be what we use for the health check (4 days ago) (Shawn Zeller) * d778846 | merge autoZK to dev (8 days ago) (austin chau) |\ | * a205cc4 | use latest debian plugin (8 days ago) (austin chau)Pull another working tree into your tree. Essentially does the following:
Figure out what is the latest commit that both trees share Apply all the changes to the working copy Optional: Allow the user to resolve any conflicts Create a merge commit with the results of the merge that references both trees
Note: In the case of trivial merges, git updates the current branch to simply reference the HEAD commit for the branch to merge.
What this really means is that reverting merge commits is a pain. Also, it makes unraveling the history of the repo, equally painful.
So, Shawn, what should we do to manage all of these branches that you tell us to have?
Like many git commands, you can use rebase for a lot of things. However, there are two main uses for rebase.
In interactive mode, it allows you to reorder, merge, alter, etc. some set of commits. Used instead of merge, it allows you to take all of your commits and place them at the end of a treepick 2cad4d7 add some entries to .gitignore pick 337330e restore /registry pick 4ba0f66 checkin some great stuff pick ff2f4cd checkin some even better stuff # Rebase ac0b6a7..ff2f4cd onto ac0b6a7 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
You have a feature branch named foo branched off of master. Since branching, more commits went into master.
git checkout foo git rebase master
git reset master git add . git ci -m "one commit with everything that was in foo"