Advanced use of git - Ugo Jardonnet

Advanced use of git. Ugo Jardonnet. February 9, 2015 .... Get in touch with the guy who made the upstream change. If the issue is a thread of commits that all ...
330KB taille 1 téléchargements 291 vues
Advanced use of git Ugo Jardonnet

February 9, 2015 Ugo Jardonnet

Advanced use of git

1 / 17

Table of Contents 1

Making your life easier with git

2

Merge and Rebase merge rebase [-i]

3

Troobleshooting Edit commit in history Conflicts Things went bad Cancel Merge

4

References

Ugo Jardonnet

Advanced use of git

2 / 17

Making your life easier with git

Outline 1

Making your life easier with git

2

Merge and Rebase merge rebase [-i]

3

Troobleshooting Edit commit in history Conflicts Things went bad Cancel Merge

4

References

Ugo Jardonnet

Advanced use of git

3 / 17

Making your life easier with git

May the terminal help you Make your life easier Put branch name in your prompt Use aliases ∼/.gitconfig 1 [ color ] 2 ui = true 3 [ alias ] 4 co = checkout 5 ci = commit 6 st = status 7 br = branch 8 [ push ] 9 default = simple

Ugo Jardonnet

Advanced use of git

4 / 17

Making your life easier with git

git gui / gitk

git gui $ sudo apt-get install git-gui Review changes on HEAD Stage / unstage files or portions of file Amend last commit Commit / Push gitk $ sudo apt-get install gitk gitk : current branch history, cherry-pick commits, create branches/tags gitk –all : history of all branches gitk filename : history of a specific file

Ugo Jardonnet

Advanced use of git

5 / 17

Merge and Rebase

Outline 1

Making your life easier with git

2

Merge and Rebase merge rebase [-i]

3

Troobleshooting Edit commit in history Conflicts Things went bad Cancel Merge

4

References

Ugo Jardonnet

Advanced use of git

6 / 17

Merge and Rebase

merge

Merge $ git merge origin/master After Merging

Before

Reminder git pull means (master)$ git fetch origin # up-to-date origin (master)$ git merge origin/master # merge with origin/master

Ugo Jardonnet

Advanced use of git

7 / 17

Merge and Rebase

rebase [-i]

Rebase $ git rebase origin/master After Rebase

Before

Reminder A commit is identified by its hash. If the content, the author or the parent of this commit changed, the hash is changed

Ugo Jardonnet

Advanced use of git

8 / 17

Merge and Rebase

rebase [-i]

Interactive Rebase Interactive rebase allows you to specifies what you want to do with commits when applied to the target branch. git rebase -i origin/master

Ugo Jardonnet

Advanced use of git

9 / 17

Troobleshooting

Outline 1

Making your life easier with git

2

Merge and Rebase merge rebase [-i]

3

Troobleshooting Edit commit in history Conflicts Things went bad Cancel Merge

4

References

Ugo Jardonnet

Advanced use of git

10 / 17

Troobleshooting

Edit commit in history

How do I edit intermediate commits I pushed for review ? Do an interactive rebase and mark the commit for edition (master)$ git fetch (master)$ git rebase -i origin/master

Git will stop the rebase at this commit. You can now amend the current commit (master)$ git add ...# add edited files (master)$ git commit --amend ... # or with git gui (master)$ git rebase --continue # when you are done If anything goes wrong (master)$ git rebase --abort # everything after rebase started is cancelled Ugo Jardonnet

Advanced use of git

11 / 17

Troobleshooting

Conflicts

When I rebase to master I get too many conflicts Rebase regularly it should will be fine

Yes... but I still don’t manage to rebase... If the conflicts affect only one commit. We need to resolve them anyway. Get in touch with the guy who made the upstream change. If the issue is a thread of commits that all conflicts when rebasing. It means you spend too much time without pushing code or rebasing. See next subsection.

Ugo Jardonnet

Advanced use of git

12 / 17

Troobleshooting

Things went bad

I went to the point of no return. Please God help me !

Start over again from master with your modification unstaged (master)$ git fetch origin # update origin (master)$ git merge origin/master # get the latest changes (master)$ git reset --soft origin/master # reset to origin/master but keep modifications

Ugo Jardonnet

Advanced use of git

13 / 17

Troobleshooting

Cancel Merge

I merged by mistake. How to undo a merge.

Remove the merge commit (master)$ git reset --hard HEAD^ # reset branch to one commit before HEAD

Ugo Jardonnet

Advanced use of git

14 / 17

References

Outline 1

Making your life easier with git

2

Merge and Rebase merge rebase [-i]

3

Troobleshooting Edit commit in history Conflicts Things went bad Cancel Merge

4

References

Ugo Jardonnet

Advanced use of git

15 / 17

References

References

http://gitimmersion.com/ http://progit.org/ http://gitready.com/ http://book.git-scm.com/ and of course stackoverflow ...

Ugo Jardonnet

Advanced use of git

16 / 17

References

Questions

Questions ?

Ugo Jardonnet

Advanced use of git

17 / 17