Dies ist eine alte Version des Dokuments!


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)
misc/git.1354310044.txt.gz · Zuletzt geändert: 2012/11/30 22:14 von 84.56.1.83