More Git Notes

Neo4J and Github trainer Peter Bell was at the Austin Groovy and Grails User Group a couple of weeks ago. He gave some git tips and tricks. I took notes. The guys at AGGUG said they would have something online. So far I have not seen anything, so I am posting my notes.

These are unedited, so you have to mentally parse it yourself. But there were a few things I did not know about.

start gitconfig
You can use the properties as setters and getters
git config –global
git config –global “Daffy Duck”
True for Windows
git config –global core.autocrlf true input
Colors for different status in git
git config –global color.ui true
Can be global, local
global is for every repo
local is the default, for a repo
system is not used too often. This is for all the users of that system.
It is in ~/.gitignore

To create a repo:
git init webgg1
cd webgg1
You might touch a file just to make a file
touch slslsls
git add .
git commit -m “Hello”
Status in silent mode: reduces the output
git status -s
git config –global alias.s “status -s”
Now you can type
git s
git log has bad default output
git log –oneline
git log –oneline –decorate
HEAD is the commit branch you currently have checked out
git log –oneline –decorate –all –graph
git config –global alias.lg “log –online –all –decorate –graph”
The alias is after the alias.
You want to commit to a different branch than master.
git checkout -b about_us
Any untracked files from master come with you
For a modified file (will not work for new files):
git commit -am “djdj”
git merge sjsjs
That is a fast forward merge.
He does not like that.
First he must undo the merge:
git reset –keep master@{1}
Go back one step in the ref log

git merge –no-ff $BRANCH -m “Hello”

git branch -d about_us
He likes to delete a branch when he commits
Merge other branches into master
I always thought you do the opposite: Never mess with master

TO remove a commit:
git reset –hard head~1

rebasing: a branch has a starting point from which it grew
Could we move the base to somewhere else
git rebase master
You might get a merge conflict.
git rebase –continue
If you delete branches and do not do fast forward commits, you still see the commits from those other branches

git reset will undo commits
–soft affects history
–mixed affects staging area as well
–hard affects working directory

We want the two new files, but undo the commits. This will undo 2 commits
git reset HEAD~2
git commit -m “jjs”

Make the last two commits into one commit
git reset –soft HEAD~2
git commit -m “hddh”

Once you push to a server, reset will be bad news
git revert $SHA_CODE

git reset –hard HEAD~2
That will delete history and the files

git ref log will track everything, it is local to each machine.
You can still reset

git commit -m “Logic stuff adofhdofh”
git commit –amend
that only affects the last commit

git rebase interactive will take commits and reorder them or concatenate them
git rebase -i HEAD~4
r = reword
f = fix up
Squash will add all the commit message. You just want to reword the first, fix the rest.

Image from “Capitulare evangeliorum (1r-16v).Evangelia quattuor (16v-275r) [Évangiles dits de Charles IX]”, a 9th century manuscript housed at the Bibliothèque nationale de France. Source / BnF; image assumed allowed under Fair Use.