Git beyond basics
-
Upload
kalpa-pathum-welivitigoda -
Category
Software
-
view
81 -
download
0
Transcript of Git beyond basics
Senior Software EngineerKalpa Welivitigoda
Git | Beyond Basics
**
๏ Initializing a git repository
๏ Adding files
๏ Committing
๏ Adding remotes
๏ Push/Pull
๏ Status
What we know already
**
WSO2/product-as john/product-as
John’s local filesystem
product-as
Fork
Clone(origin)
Remote(upstream)
**
We are no alone!
WSO2/product-as bill/product-as
john/product-asJohn’s local filesystem
product-as
bob/product-as
Bill’s local filesystem
product-as
Bob’s local filesystem
product-as
**
Developing a feature
**
Keep up with the changes...
**
MergeVs.
Rebase
**
git merge
$ git checkout feature $ git merge master
๏ Non destructive mechanism
๏ Additional commit
**
git rebase
$ git checkout feature $ git rebase master
๏ Cleaner commit history
๏ Rewrites the history!!!!
**
๏ Very powerful
๏ Clean the commit history before merging to master
branch
$ git rebase -i HEAD~10
Interactive rebase
# Commands:p, pick = use commitr, reword = use commit, but edit the commit messagee, edit = use commit, but stop for amendings, squash = use commit, but meld into previous commitf, fixup = like "squash", but discard this commit's log messagex, exec = run command (the rest of the line) using shelld, drop = remove commit
**
Split commits | Demo
**
git stash
๏ A stack of uncommitted changes
๏ Tracks modified files and staged changes
๏ Useful when switching between branches
**
$ git stash$ git stash save stash1
git stash...
$ git stash list
$ git stash apply$ git stash apply stash@{1}
$ git stash drop
$ git stash pop
$ git stash -p
$ git checkout stash@{n} -- {{file_path}}
**
Selective stashing | Demo
**
$ git log --oneline$ git log --decorate$ git log --stat$ git log -- graph --oneline --decorate $ git shortlog
$ gitk
git log
Log formatting
**
$ git log -3
$ git log --after="2016-09-01"$ git log --after="yesterday"$ git log --after="1 week ago"
$ git log --author="John\|Mary"
$ git log --grep="WSAS"
$ git log -- pom.xml
$ git log -S "maven-deploy-plugin"
$ git log --no-merges$ git log -- merges$ git log <since>...<until>
git log...Log filtering
**
$ git config --global alias.lo "log --oneline"
$ git lo
git alias
**
$ git checkout feature$ git cherry-pick 5a63064
git cherry-pick
๏ It’s a new commit !!!!
**
$ git reflog
git reflog
๏ git log shows commits in ancestor order
๏ Reflog shows in the order you last referenced the
commits
**
$ git bisect start$ git bisect good <good commit hash>$ git bisect bad <bad commit hash>
$ git bisect reset
git bisect
๏ Used to find the commit that introduced a bug/fix
๏ Do a binary search of the commits
**
Git best practices
๏ Develop features in feature branches
๏ Commit often, perfect later, publish once
๏ Never change published history (it is possible with
push -f, but never ever do it)
๏ Keep your git tree clean (git pull upstream master --rebase)
**
Git best practices...๏ A commit message has a subject and a body.
๏ Make the commit subject imperative
๏ Link to the JIRA/Git Issue ID
๏ WSAS-1169 : <commit subject>
๏ Resolves #21
**
Reference
๏ https://www.atlassian.com/git/tutorials/advanced-ov
erview
๏ http://chris.beams.io/posts/git-commit/
๏ https://git-scm.com/doc
**
Questions ?
**
Thank You !