The 7 Things I Know About Cyber Security After 25 Years | April 2024
Git back on_your_feet
1. Git back on your Feet
February, 2016
Christian Couder
chriscool@tuxfamily.org
Git-Paris Meetup
2. A Distributed Version Control System (DVCS):
● created by Linus Torvalds
● maintained by Junio Hamano
● since 2005
● preferred VCS
About Git
3. ● started developing Git in 2006
● worked especially on git bisect
● independent consultant working on Git and IPFS
● give presentations about Git since 2009
● edit Git Rev News
About myself
5. Frequent Use Case
You do something and then:
● What? You're talking to me?
● Help! I don't know the current state I am in!
● I don't know WTF happened!
● I don't know how to git back on my feet!
6. Why “backup everything and clone again” is not a
good solution?
● You will learn nothing
● You are very likely to lose time
● You are likely to get back to the same state again
● You are likely to get frustrated
7. So what is the solution?
Try to answer the questions you would like to ask:
● What does the message mean?
● What is the current state?
● What happened?
● How can I git back on my feet?
8. What does the message mean? (1)
● Read carefully what git told you
● git help glossary, and other git help features
● Use a recent git version
● Use (LANG=fr) or don't use a localized Git (LANG=C)
● Google the message!
● Try to learn a bit about Git architecture
9. What does the message mean? (2)
git help demo:
● git help <cmd>
● git help glossary
● git help
● git help -a
● git help -g
● git help -w
10. What does the message mean? (3)
Demo git-man-page-generator:
https://git-man-page-generator.lokaltog.net/
11. What state I am in? (1)
Use some commands like:
● git status
● git branch, git describe
● git diff (--cached), git show
● git log, and it's very useful options:
--oneline --decorate --graph --all
12. What state I am in? (2)
Visualize more:
● Command line prompt
● Gitk, graphical clients (SourceTree, GitHub Desktop,...)
● git difftool and git mergetool can launch: p4merge, meld,
gvimdiff3, emerge, bc3, kdiff3, kompare, …
● Draw a diagram
13. Diagram example 1
commit <size>
SHA1: e84c7...
parent
tree 29c43...
author Christian <ts>
committer Christian <ts>
Initial commit
tree <size>
blob
tree
38d72...hello.c
doc 98ca9...
commit <size>
SHA1: 98ca9...
parent
tree 5c11f...
e84c7...
author Arnaud <ts>
committer Arnaud <ts>
Change hello.c
SHA1: 29c43...
tree <size>
blob
blob
677f4...readme
install 23ae9...
SHA1: 98ca9...
tree <size>
blob
tree
bc789...hello.c
doc 98ca9...
SHA1: 5c11f...
blob <size>
SHA1: 38d72...
int main() { ... }
blob <size>
SHA1: bc789...
int main(void) { ... }
15. What state I am in? (3)
Demos:
● git log --oneline --decorate --graph
● Merge conflict
● git mergetool
16. Example: merge with conflicts
● Use « git diff » and « git status » to see where are the
conflicts
● Some file will have conflicts makers inserted (<<<<<< …
====== … >>>>>>)
● Edit those files to fix conflicts and remove markers
● Use « git add » to say that conflicts are fixed
● Use « git commit » when merging or « git rebase
--continue » when rebasing
17. What happened? (1)
● Use your shell history
● git reflog <branch>
● ls -lrt .git/refs/heads/
● Try to replay what happened on a cloned repo or on
different branches
19. How can I git back on my feet? (1)
● git <cmd> --abort, e. g. git rebase --abort
● git reset, but be careful
● git checkout <file>, but be careful
● git clean (-dfx), but be very careful
● git stash, git commit, git diff, git apply (-R), be also careful
● git fsck, as a last resort
20. How can I git back on my feet? (2)
Five types of reset:
● --soft
● --mixed (default)
● --hard
● --merge
● --keep
21. How can I git back on my feet? (3)
The trick is not losing data! If possible:
● Create a branch:
git checkout -b <new_branch>
● Commit everything on this branch and push it:
git add, git commit, git push
● Go back to the previous branch:
git checkout <old_branch>
22. How can I git back on my feet? (4)
Demo: git reset --keep
Use case:
● git checkout master
● Hack, hack
● Git commit
● Ooops, I need to commit on a feature branch, not on
master!
24. Conclusion
● Git has a lot of great documentation everywhere,
but you need to be used to it
● git reset is not so difficult to understand
● It's not so difficult to quickly git back on your feet
without losing your data