• Tracking project history • Searching for a change in the code • Revert changes, when something is broken or not desired in the upcoming release • Integrating work within a team • Verify changes before they will become part of the shipped product • Increase project quality
for maintaining Linux kernel • Created by Linus Torvalds (creator of Linux) • Its goal was to create distributed VCS (opposite idea to existing, centralized systems)
# and edit commit message inside your favourite editor Remember about writing good and descriptive commit messages! It helps in browsing and analyzing log as well as keeping project history clean. Links: • https://chris.beams.io/posts/git-commit/ • https://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message • http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html • https://github.com/pwittchen/craplog
edit commits in your editor pick 740077e adding NOTES.md file squash 9099c9d Update README.md squash 1c9cbe4 Revert "Update README.md" # update commit message git commit --amend Rebase helps to keep history clean. Be very careful with rewriting history, because you can loose the code, when you do something wrong! Know what you do! Read more at: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History Rewriting the history git rebase -i HEAD~3 git commit --amend squashed commits: 1, 2, 3 brand new commit message
undo last commit on the current branch git reset --hard HEAD~1 # undo last commit and move it into staging area git reset --soft HEAD~1 # create revert commit for a given change git revert 9099c9d
staging area git reset --soft HEAD~1 make changes decide to undo changes git reset --soft HEAD~1 work from the scratch again commit staging area Note: if we already pushed changes to remote repository, We need to push changes with force next time (git push -f). Sometimes it may be blocked and not possible.
git stash list # apply stashed changes git stash apply # to clear stash list git stash clear # to drop one item git stash drop stash@{0} # to apply and drop git stash pop make changes without commit stop the work git stash work on something else git stash apply
and web UI: • https://github.com • https://bitbucket.org • https://gitlab.com They’re also open-source ecosystems and services with many integrations (e.g. CI servers) used by professionals, students and hobbyists. Most of them are free for open-source!
Git! • Use Git from terminal • Learn about the commands before you use them • Try to experiment on a “dummy” project before using it in a serious project • Use Git Flow • Use aliases • Review your changes before the commit • Care about commit messages • Be careful and know what you do • If you don’t know how to do something, then read, learn, experiment and ask others for help or an explanation