GIT

Zubeginn ist alles leer (Working directory & Index):

$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
$ git ls-files --debug -s

Anlegen eines zweier files, wovon eins in den Index kommt (stage)

$ touch unused
$ touch foo
$ git add foo
$ git commit -a -m "Added foo"
[master (root-commit) 5f3450e] Added foo
 0 files changed
 create mode 100644 foo
$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	unused
nothing added to commit but untracked files present (use "git add" to track)
$ git ls-files --debug -s
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	foo
  ctime: 1354306311:692664264
  mtime: 1354306311:692664264
  dev: 28	ino: 119763
  uid: 1000	gid: 1000
  size: 0	flags: 0

foo touchen, aber nicht den Inhalt verändern

$ touch foo

Keine Änderung wird erkannt & Neue m-time:

$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	unused
nothing added to commit but untracked files present (use "git add" to track)
$ git ls-files --debug -s
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	foo
  ctime: 1354306421:958755979
  mtime: 1354306421:958755979
  dev: 28	ino: 119763
  uid: 1000	gid: 1000
  size: 0	flags: 0

foo touchen & Inhalt verändern:

$ echo "content" > foo

Änderung erkannt & m-time bleibt alt:

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   foo
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	unused
no changes added to commit (use "git add" and/or "git commit -a"):
$ git ls-files --debug -s
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	foo
  ctime: 1354306421:958755979
  mtime: 1354306421:958755979
  dev: 28	ino: 119763
  uid: 1000	gid: 1000
  size: 0	flags: 0

foo In den Index hinzufügen (stagen):

$ git add foo

Änderungen übernommen (neue SHA1) & neue m-time:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   foo
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	unused
$ git ls-files --debug -s
100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0	foo
  ctime: 1354306489:705068567
  mtime: 1354306489:705068567
  dev: 28	ino: 119763
  uid: 1000	gid: 1000
  size: 8	flags: 0

Committen:

$ git commit -a -m "Modified foo"
[master fc724cf] Modified foo
 1 file changed, 1 insertion(+)

Index bleibt unverändert:

$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	unused
nothing added to commit but untracked files present (use "git add" to track)
$ git ls-files --debug -s
100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0	foo
  ctime: 1354306489:705068567
  mtime: 1354306489:705068567
  dev: 28	ino: 119763
  uid: 1000	gid: 1000
  size: 8	flags: 0
  • Index ist immer über alle getrackten Dateien.
    ⇒ Untracked files sind nicht im Index.
    ⇒ Sie werden nicht committed.
$ cp old new
$ git rm old
rm 'old'
$ git add new
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	renamed:    old -> new
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	unused
$ git commit -a -m "renaming"
[master 289cf21] renaming
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename old => new (100%)
  • File moves werden nicht protokolliert, sondern on-demand heuristisch erkannt
  • Ein Commit ist ein eingefrorener Index zustand (über alle getrackten Dateien/Ordner, egal ob geändert oder nicht)
  • Da Index \ne Working copy sein kann, sind alle Dateien/Ordner im Index links auf GIT Objekte

Wichtige Befehle

Befehl Bedeutung
git add -p <file> Wähle aus welche Änderungen in den Index sollen
git diff [<file>] Working coppy VS. Index (of a file)
git diff –cached [<file>] Index VS. HEAD (of a file)
git log [<file>] Commit history (of a file)
git show <ID> Commit message + diffs
git cat-file -p <ID> Zeige GIT Objekte aus dem object strorre
git clone <URL>
git submodule init
git submodule update
Repo mit submodulen inizialisieren (clonen)
(submodule müssen extra explizit behandelt werden)

Dateistruktur

Objects

/objects/<xx>/<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>

Können entweder mit

for x in t s p ; do git cat-file -$x 3d646c3d1bf84007c93ab1d78e7f6941ef65bdc2 ; done

oder mit

  perl -MCompress::Zlib -e 'undef $/; print uncompress(<>)' .git/objects/28/9cf21ee611ca2c335fa77f48f4613bd5255aa3

angeschaut werden

Refs

/refs/

In Ordnern sind files die einen Hash enthalten. Somit Wird einem GIT object ein Name gegeben.

/HEAD

Referenz auf eine file in /refs. Ist link auf den aktuellen HEAD des aktuellen branches und somit indirekt auf den letzten commit.

Tags

/refs/tags/<tag name>

<tag name> ist eine datei die den Hash eines der follgenden Objekte enthält

Was Tag typ
tag object Annotiated Tag
blob object Leightweight Tag
tree object
commit object
  • Ein tag object kann auf alle 4 Typen (auch tags selbst) wieder verweisen
  • Nur annotiated tags können commitet werden (sie sind ja schließlich eigene objekte. Commits als tags könnten nicht vom commit selbst unterschieden werden)
  • Annotiated Tags werden standartmäsig nicht committed (???)
  • Annotiated tags sind zu bevorzugen, da dort u.a. auch der ersteller gespeichert wird.
misc/git.txt · Zuletzt geändert: 2016/05/19 12:19 von skruppy