Git: Unterschied zwischen den Versionen
(→Tagging) |
(→Tipps and tricks) |
||
Zeile 115: | Zeile 115: | ||
=Tipps and tricks= | =Tipps and tricks= | ||
+ | ==Use stash== | ||
+ | Stash: Verstauen. 'Versorgt' die aktuellen Änderungen in einer Schublade, um es später wieder hervorzunehmen. Nützlich, wenn | ||
+ | man Änderungen hat, die man noch nicht committen will, aber kurzzeitig zu einem anderen Projekt bzw. Branch wechseln will. | ||
+ | |||
+ | <pre>git stash list</pre> | ||
+ | :Lists the stashes | ||
+ | |||
+ | <pre>git stash save no idea what i'm doing here</pre> | ||
+ | :Save your local modifications to a new stash, and run git reset --hard to revert them. Saves with message: 'no idea what i'm doing here' | ||
+ | |||
+ | <pre>git stash pop stash@{0}</pre> | ||
+ | :Remove a single stashed state from the stash list and apply it on top of the current working tree state | ||
+ | |||
+ | <pre>git stash apply stash@{0}</pre> | ||
+ | :Like pop, but do not remove the state from the stash list | ||
+ | |||
+ | <pre>git stash drop stash@{0}</pre> | ||
+ | :Remove a single stashed state from the stash list | ||
+ | |||
+ | <pre>git stash show stash@{0}</pre> | ||
+ | :show changes | ||
=Some command notes= | =Some command notes= |
Version vom 23. Februar 2012, 14:51 Uhr
Inhaltsverzeichnis
Basics
Git is a Distributed Version Control System (DVCS).
Local Operations
- Working directory
- Files where you work
- Staging Area
- Staged diffs are ready to be committed
- git repository
- Committed files
Config
- System (/etc/gitconfig)
- git config --system
- Global (~/.gitconfig)
- git config --global
- Repository (%WORKINGDIRECTORY%/.git/config)
- git config --local
Ignoring files
In workingdirectory:
vim .gitignore
Working local
Clone existing Repository
git clone git://github.com/schacon/grit.git
- That creates a directory named "grit", initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version
git clone git://github.com/schacon/grit.git mygrit
- Creates "mygrit" directory instead of "grit"
Check Status
git status
Show log
git logoder
gitk
git log --stat
Mit Zusammenfssung der Änderungen
Formatting output
git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"
git log --pretty=format:"%h %s" --graph
Limit output
git log --since=2.weeks
git log --2
git log --pretty="%h - %s" --author=gitster --since="2008-10-01" --before="2008-11-01" --no-merges
Stage files
A modified file under version control can be staged with the command
git addor use
git gui
git add is also used to add new files to version control.
Commit files
git commit
git commit -m 'initial project version'
Remove files
git rm readme.txt
deletes the readme.txt file from working directory (file is really deleted) and from version control.
git rm --cached readme.txt
deletes the readme.txt file from version control, but not from working directory (file is still on filesystem).
Working with Remotes
You must have cloned an existing Repository before working with remotes. See Clone existing Repository
Show remote repositories
git remote
git remote -v
Adding Remote Repositories
git remote add mic git@git.imis.intra:~mic/ishop-ap/mic-ishop-ap.git
Update repository
gets all changes from mic without merge:
git fetch mic
git fetch origin
gets all changes from mic and merges to current branch (or master):
git pull origin
Pushing to Remotes
git push [remote-name] [branch-name]
git push origin masterPushes your master branch to your origin server
Inspecting a Remote
git remote show origin
Tagging
List tags
git tag
git tag -l '2.0.*'lists only tags matching '2.0.*'-pattern
Create tags
- lightweight (eg. for temporary use)
- like a branch that doesn’t change — it’s just a pointer to a specific commit
- annotated (recommended)
- are stored as full objects in the Git database. They’re checksummed, contain the tagger name, e-mail, and date, have a tagging message;
Annotated
git tag -a v1.4 -m 'my version 1.4'
Lightweight
git tag v1.4-1
Tipps and tricks
Use stash
Stash: Verstauen. 'Versorgt' die aktuellen Änderungen in einer Schublade, um es später wieder hervorzunehmen. Nützlich, wenn man Änderungen hat, die man noch nicht committen will, aber kurzzeitig zu einem anderen Projekt bzw. Branch wechseln will.
git stash list
- Lists the stashes
git stash save no idea what i'm doing here
- Save your local modifications to a new stash, and run git reset --hard to revert them. Saves with message: 'no idea what i'm doing here'
git stash pop stash@{0}
- Remove a single stashed state from the stash list and apply it on top of the current working tree state
git stash apply stash@{0}
- Like pop, but do not remove the state from the stash list
git stash drop stash@{0}
- Remove a single stashed state from the stash list
git stash show stash@{0}
- show changes