Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Git Tricks
git utilities
that make
life git easier
Git Logo by Jason Long (CC BY 3.0), Image by Steven Depolo (CC BY 2.0)
$ git commit --amend -m "new message"
Change commit message of previous commit
(Careful, don't do this if you already push...
$ git stash
$ git stash pop
Temporarily store/retrieve all modified tracked files
$ git stash list
List all stashed change...
$ git log --abbrev-commit --pretty=oneline
Show changesets in the log
Shorter version of the git log
$ git log -p
Show pre...
■ Easiest way to integrate the branches is merge
□ Will create merge commits
https://git-scm.com/book/en/v1/Git-Branching-...
6
$ git checkout experiment
$ git rebase master
■ Afterwards: fast-forward the master branch
□ No merge commits
$ git chec...
■ Problem: Quickly get changes from other commits
without having to merge entire branches
■ git cherry-pick
□ apply the ch...
8
Some Git Self-help Resources
■ How to undo (almost) anything with git – guide by Github
□ https://github.com/blog/2019-h...
■ Many GUIs for git available (https://git-scm.com/downloads/guis)
□ Make some complex git interactions much simpler
□ Dra...
1
Conclusion
Who did what, when, and why?
Git (and version control in general) helps answer the question
P.S. Try to avoid...
Upcoming SlideShare
Loading in …5
×

Git Tricks — git utilities that make life git easier

892 views

Published on

Excerpt from slides used in undergraduate software engineering lectures.

Our favorite git tricks, git commands and utilities that make working with git easier.

Updated June 2015.

Published in: Education
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Git Tricks — git utilities that make life git easier

  1. 1. Git Tricks git utilities that make life git easier Git Logo by Jason Long (CC BY 3.0), Image by Steven Depolo (CC BY 2.0)
  2. 2. $ git commit --amend -m "new message" Change commit message of previous commit (Careful, don't do this if you already pushed the commit) $ git add [missing files] $ git commit --amend #uses the previous commit's message Forgot to commit files? $ git reset --soft HEAD@{1} $ git commit -C HEAD@{1} Undo the amending Interactive staging (also allows committing only parts of files) $ git add -i $ git add --patch [file] 2 Git Tricks—amend, add --patch Image by drawmeanidea.com
  3. 3. $ git stash $ git stash pop Temporarily store/retrieve all modified tracked files $ git stash list List all stashed changesets What did I work on recently? Show differences that are not staged yet $ git diff Shows differences between staging and the last file version $ git diff --staged $ git reflog Log of all recent actions 3 Git Tricks—reflog, diff, stash
  4. 4. $ git log --abbrev-commit --pretty=oneline Show changesets in the log Shorter version of the git log $ git log -p Show pretty graph of git history $ git log --graph --decorate --pretty=oneline --abbrev-commit $ git rebase [branch] History is becoming cluttered with merge commits Git Tricks—log, blame, rebase $ git blame --date=short [file] Show what revision and author last modified each line 4
  5. 5. ■ Easiest way to integrate the branches is merge □ Will create merge commits https://git-scm.com/book/en/v1/Git-Branching-Rebasing (MIT) $ git checkout master $ git merge experiment $ git checkout –b "experiment" $ git commit –a –m "C3" 5 Rebase—setup ■ Created "experiment" branch to try something
  6. 6. 6 $ git checkout experiment $ git rebase master ■ Afterwards: fast-forward the master branch □ No merge commits $ git checkout master $ git merge experiment https://git-scm.com/book/en/v1/Git-Branching-Rebasing (MIT) 6 Rebase—execution ■ git rebase □ Take all the changes that were committed on one branch and replay them on another one □ Please(!) only with local commits
  7. 7. ■ Problem: Quickly get changes from other commits without having to merge entire branches ■ git cherry-pick □ apply the changes introduced by existing commits $ git checkout master $ git log --abbrev-commit --pretty=oneline d7ef34a C3: Implement feature 0be778a C4: critical change introduced C0 C1 C2 CA C3 CB C4 C5 C4 critical change master experiment $ git checkout experiment $ git cherry-pick 0be778a 7 Git cherry-pick
  8. 8. 8 Some Git Self-help Resources ■ How to undo (almost) anything with git – guide by Github □ https://github.com/blog/2019-how-to-undo-almost-anything-with-git ■ Git cheat sheet – by Github □ https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf ■ Git pretty – troubleshooting flowchart □ http://justinhileman.info/article/git-pretty/ ■ Git FAQ – answers to common questions □ http://gitfaq.org/ □ https://git.wiki.kernel.org/index.php/Git_FAQ
  9. 9. ■ Many GUIs for git available (https://git-scm.com/downloads/guis) □ Make some complex git interactions much simpler □ Draw pretty commit graphs, overviews of branches and merges □ E.g. GitX, TortoiseGit, SourceTree, Tower, SmartGit, gitg, git-cola ■ Github Integration □ Github also provides git tools (https://mac.github.com/, https://windows.github.com/) ■ Git extras (https://github.com/tj/git-extras) □ Common git commands bundled 9 Some Tooling Suggestions
  10. 10. 1 Conclusion Who did what, when, and why? Git (and version control in general) helps answer the question P.S. Try to avoid push --force. Seriously. knowing some git tricks helps you get there faster.

×