Git back on your Feet
February, 2016
Christian Couder
chriscool@tuxfamily.org
Git-Paris Meetup
A Distributed Version Control System (DVCS):
● created by Linus Torvalds
● maintained by Junio Hamano
● since 2005
● prefe...
● started developing Git in 2006
● worked especially on git bisect
● independent consultant working on Git and IPFS
● give...
Git as seen by xkcd (https://xkcd.com/1597/)
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!...
Why “backup everything and clone again” is not a
good solution?
● You will learn nothing
● You are very likely to lose tim...
So what is the solution?
Try to answer the questions you would like to ask:
● What does the message mean?
● What is the cu...
What does the message mean? (1)
● Read carefully what git told you
● git help glossary, and other git help features
● Use ...
What does the message mean? (2)
git help demo:
● git help <cmd>
● git help glossary
● git help
● git help -a
● git help -g...
What does the message mean? (3)
Demo git-man-page-generator:
https://git-man-page-generator.lokaltog.net/
What state I am in? (1)
Use some commands like:
● git status
● git branch, git describe
● git diff (--cached), git show
● ...
What state I am in? (2)
Visualize more:
● Command line prompt
● Gitk, graphical clients (SourceTree, GitHub Desktop,...)
●...
Diagram example 1
commit <size>
SHA1: e84c7...
parent
tree 29c43...
author Christian <ts>
committer Christian <ts>
Initial...
Diagram example 2
What state I am in? (3)
Demos:
● git log --oneline --decorate --graph
● Merge conflict
● git mergetool
Example: merge with conflicts
● Use « git diff » and « git status » to see where are the
conflicts
● Some file will have c...
What happened? (1)
● Use your shell history
● git reflog <branch>
● ls -lrt .git/refs/heads/
● Try to replay what happened...
What happened? (2)
Demos:
● Use your shell history
● git reflog <branch>
● ls -lrt .git/refs/heads/
How can I git back on my feet? (1)
● git <cmd> --abort, e. g. git rebase --abort
● git reset, but be careful
● git checkou...
How can I git back on my feet? (2)
Five types of reset:
● --soft
● --mixed (default)
● --hard
● --merge
● --keep
How can I git back on my feet? (3)
The trick is not losing data! If possible:
● Create a branch:
git checkout -b <new_bran...
How can I git back on my feet? (4)
Demo: git reset --keep
Use case:
● git checkout master
● Hack, hack
● Git commit
● Ooop...
● http://git-scm.com
● https://git.github.io/rev_news/archive/
● https://xkcd.com/1597/
● https://git-man-page-generator.l...
Conclusion
● Git has a lot of great documentation everywhere,
but you need to be used to it
● git reset is not so difficul...
Questions?
Próxima SlideShare
Cargando en…5
×

Git back on_your_feet

67 visualizaciones

Publicado el

How to solve some problems you can have with Git

Publicado en: Tecnología
0 comentarios
0 recomendaciones
Estadísticas
Notas
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Sin descargas
Visualizaciones
Visualizaciones totales
67
En SlideShare
0
De insertados
0
Número de insertados
1
Acciones
Compartido
0
Descargas
2
Comentarios
0
Recomendaciones
0
Insertados 0
No insertados

No hay notas en la diapositiva.

Git back on_your_feet

  1. 1. Git back on your Feet February, 2016 Christian Couder chriscool@tuxfamily.org Git-Paris Meetup
  2. 2. A Distributed Version Control System (DVCS): ● created by Linus Torvalds ● maintained by Junio Hamano ● since 2005 ● preferred VCS About Git
  3. 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
  4. 4. Git as seen by xkcd (https://xkcd.com/1597/)
  5. 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. 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. 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. 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. 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. 10. What does the message mean? (3) Demo git-man-page-generator: https://git-man-page-generator.lokaltog.net/
  11. 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. 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. 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) { ... }
  14. 14. Diagram example 2
  15. 15. What state I am in? (3) Demos: ● git log --oneline --decorate --graph ● Merge conflict ● git mergetool
  16. 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. 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
  18. 18. What happened? (2) Demos: ● Use your shell history ● git reflog <branch> ● ls -lrt .git/refs/heads/
  19. 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. 20. How can I git back on my feet? (2) Five types of reset: ● --soft ● --mixed (default) ● --hard ● --merge ● --keep
  21. 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. 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!
  23. 23. ● http://git-scm.com ● https://git.github.io/rev_news/archive/ ● https://xkcd.com/1597/ ● https://git-man-page-generator.lokaltog.net/ ● https://try.github.io/ Links
  24. 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
  25. 25. Questions?

×