git workshop

21
Git Workshop

Upload: igor-popov

Post on 14-Jul-2015

85 views

Category:

Technology


0 download

TRANSCRIPT

Git Workshop

Discussion items

• How to merge

• Branches with one commit

• Reverts

How to merge

How to merge

• It’s simple!

1. Make sure the source and destination branch are up to date

2. Merge and solve conflicts

3. Run all the tests

4. Push to remote repository

How to merge

1. Make sure the source and destination branch are up to date

; deal with the source_branch

• git checkout source_branch

• git pull --rebase origin source_branch

; deal with the destination_branch

• git checkout destination_branch

• git pull --rebase origin destination_branch

; sometimes the branches are not updated so we (always) need to:

• git fetch

How to merge

2. Merge and solve conflicts • git merge --no-ff source_branch

• Optional (only if you have conflicts): – git mergetool –y

– git add -A <all the files that had a conflict>

– git commit -sv

How to merge

3. Run all the tests

• gradlew --offline clean check

• gradlew --offline clean runPdiTests

• If tests fail: FIX THEM before you continue!

How to merge

4. Push to remote repository

• git push origin destination_branch

How to merge

Stuff that can go wrong

someone might have pushed something while you were doing the merge

How to merge

How to deal with this

• Simple solution: before a merge tell the team not to put anything on the destination branch

• Not so simple: reset everything and start again – git checkout destination_branch

– git reset --hard origin/destination_branch

– start over (update the branches, etc)

Branches with one commit

Branches with one commit

• NO! If you have a single commit do NOT create a new branch.

If you do create a new branch you should use:

git merge source_branch

instead of

git merge --no-ff source_branch

Branches with one commit

Simple rule – 1 commit --> no branch

– > 1 commit --> create branch

Branches with one commit

Bad vs. good enough

Reverts

Reverts

Reverting the last LOCAL commit:

git reset --hard HEAD~

Or

git reset --hard <commit hash>

Reverts

Reverting any PUSHED commit:

git revert <commit hash>

Reverts

Reverting more than 1 PUSHED commit:

git revert <commit1 hash>

git revert <commit2 hash>

git rebase –i HEAD~2

; reword + fixup/squash

Reverts

Reverting more than 1 PUSHED commit:

Example:

Reverts

Reverting a LOCAL merge:

git reset --hard ORIG_HEAD

Reverts

Reverting a PUSHED merge:

git checkout <branch with merge>

git revert -m 1 <merge commit hash>