Code and Data Management With Git: The Git Commit Graph
Code and Data Management With Git: The Git Commit Graph
Table of contents
A linear history
12f82a1 H
1d438b8
A linear history
2f5458a H
2f5458a
1d438b8
2f5458a H
2f5458a
1d438b8
2f5458a
The working directory reects
the les state from the commit
to which the HEAD points to.
2f5458a
1d438b8
Committing
Committing moves the current
master HEAD
branch to the new commit.
12f82a1
H
it.
master HEAD
2f5458a
2f5458a
1d438b8
Committing
Committing moves the current
master HEAD
branch to the new commit.
12f82a1
2f5458a
2f5458a
1d438b8
A non-linear history
2f5458a 441aa8c
S"#$
parent
2f5458a
1d438b8
2f5458a 441aa8c
2f5458a
1d438b8
Merging
another feature master HEAD Bringing together commits
4564aaf a12a223 from di%erent branches.
some feature
11a5645 12f82a1 33215af
2f5458a 441aa8c
2f5458a
1d438b8
Table of contents
An example repository
master HEAD
c7f3bd9
Add .gitignore file interface
8fc25c1
Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee
Add course teachers license
to README
0fbe3e3
Add MIT license
d1c7fd7
Initial commit with README
$ git status
On branch master
nothing to commit, working directory clean.
Listing branches
$ git branch
interface
license
* master
Listing branches
$ git branch
interface
license
* master
$ git branch -v
interface 8fc25c1 Trivial Python interface
license 0fbe3e3 Add MIT license
* master c7f3bd9 Add .gitignore file
Table of contents
$ git status
On branch interface
nothing to commit, working directory clean.
master HEAD
c7f3bd9
Add .gitignore file interface
8fc25c1
Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee
Add course teachers license
to README
0fbe3e3
Add MIT license
d1c7fd7
Initial commit with README
master
c7f3bd9
Add .gitignore file interface
8fc25c1
Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee
Add course teachers license
to README
0fbe3e3
Add MIT license
d1c7fd7
Initial commit with README
$ git status
HEAD detached at 4a44c4e
nothing to commit, working directory clean.
master
c7f3bd9
Add .gitignore file interface
8fc25c1
Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee
Add course teachers license
to README
0fbe3e3
Add MIT license
d1c7fd7
Initial commit with README
master
c7f3bd9
Add .gitignore file interface
8fc25c1
Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee
Add course teachers license
to README
0fbe3e3
Add MIT license
d1c7fd7
Initial commit with README
master
c7f3bd9
Add .gitignore file interface
8fc25c1
Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee
Add course teachers license
to README
0fbe3e3
Add MIT license
d1c7fd7
Initial commit with README
Table of contents
$ git branch
interface
lib
license
* master
$ git branch
interface
lib
license
* master
c7f3bd9
Add .gitignore file interface
8fc25c1
Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee
Add course teachers license
to README
0fbe3e3
Add MIT license
d1c7fd7
Initial commit with README
Working on a branch
We can extend the lib branch by adding commits.
Working on a branch
We can extend the lib branch by adding commits.
251a51b
Add empty testlib
master interface
c7f3bd9 8fc25c1
Add .gitignore file Trivial Python interface
4a44c4e
Merge Branch 'license'
license
64af1ee 0fbe3e3
Add course teachers Add MIT license
to README
d1c7fd7
Initial commit with README
251a51b
Add empty testlib
4a44c4e
Merge Branch 'license'
license
64af1ee 0fbe3e3
Add course teachers Add MIT license
to README
d1c7fd7
Initial commit with README
Three-way merging
Let’s merge our work on interface back into master.
fc054a6
Merge branch 'interface'
into characters
251a51b
Add empty testlib
interface
c7f3bd9 8fc25c1
Add .gitignore file Trivial Python interface
4a44c4e
Merge Branch 'license'
license
64af1ee 0fbe3e3
Add course teachers Add MIT license
to README
fc054a6
Merge branch 'interface'
into characters
lib
251a51b
Add empty testlib
interface
c7f3bd9 8fc25c1
Add .gitignore file Trivial Python interface
4a44c4e
Merge Branch 'license'
license
64af1ee 0fbe3e3
Add course teachers Add MIT license
to README
Note
Make sure that the working directory is clean before merging.
Otherwise:
Deleting branches
Old branches that have been merged can be deleted.
Deleting branches
master HEAD
fc054a6
Merge branch 'interface'
into characters
251a51b
Add empty testlib
c7f3bd9 8fc25c1
Add .gitignore file Trivial Python interface
4a44c4e
Merge Branch 'license'
64af1ee 0fbe3e3
Add course teachers Add MIT license
to README
d1c7fd7
Initial commit with README
40/54 Code and data management with Git 14-06-2019
Basic merge conflicts
Table of contents
Merge conflicts
Git is pretty good at merging:
• The changes might have been in different files.
• Or in different parts of the same file.
• Git tries to figure out a sensible result.
Merge conflicts
Git is pretty good at merging:
• The changes might have been in different files.
• Or in different parts of the same file.
• Git tries to figure out a sensible result.
$ git show
f1ef19c State character preference
diff --git a/FACTS.md b/FACTS.md
index de15194..ef40359 100644
--- a/FACTS.md
+++ b/FACTS.md
@@ -1,2 +1,4 @@
Facts about television series
=============================
+
+My favorite character is Eric Cartman.
$ cat FACTS.md
Facts about television series
=============================
S
<<<<<<< HEAD
My favorite character is Eric Cartman.
=======
My favorite character is Milhouse.
>>>>>>> hue
$ nano FACTS.md
$ cat FACTS.md
Facts about television series
=============================
S
My favorite characters are Eric Cartman
and Milhouse.
Aborting a merge
If you don’t feel like resolving the merge conflict, you can go back
with git merge --abort.
$ git mergetool
merge tool candidates: meld opendiff kdiff3 ...
Merging:
FACTS.md
S
Normal merge conflict for ’FACTS.md’:
sslocal: modified file
ssremote: modified file
Hit return to start merge resolution tool (meld):
Meld example
Martijn Vermaat
Wibowo Arindrarto
Szymon Kielbasa
Jeroen Laros
http://git-scm.com/book
https://www.atlassian.com/git