Skip to main content

Posts about vcs

git

オープンソースの分散型VCS。同種のアプリケーションと比較してgitが優れているところは、ユーザが多く情報が多いという点。

gitリポジトリの作成

cd myproject
git init
git add .
git status
git diff
git rm [-r] target # -rで、ディレクトリを削除
git commit -m "commit message"
git log

作業ディレクトリを持たない公開用リポジトリの作成

git init --bare
or
git clone --bare myproject myproject.git

git log
git branch

単純なリモート作業

git clone git://example.com/.../myproject.git # リポジトリのclone
cd myproject
:
git push [origin] [master] # 変更内容をpush

git pull # fetchしてmerge

ブランチを作成し作業対象とする

git branch master
git pull
git checkout -b mybranch
git branch

masterブランチにマージ。不要なブランチの削除

git checkout master
git merge mybranch
git branch -d mybranch

ブランチをリモートにpush

git push origin mybranch

ブランチをリモートからfetchして作業

git fetch origin
git branch -a
git checkout -b mybranch origin/mybranch # ブランチを作成してチェックアウト

リモートブランチの削除

git push origin :mybranch

change last commit

git add file
git commit --amend -m "commit message"
git push -f origin master

Stash the changes in a dirty working directory away

git stash
git stash list
git stash show -p stash@{0}

apply stash on top of the current working directory. and remove a stash from the list

git stash apply stash@{0}
git stash drop stash@{0}

reset indext to cancel add operation and leave the file as it is

git reset HEAD xxxx.txt

ignore file permission change (chmod)

git config --local core.filemode false
git config --local --list

example of URIs

ssh://username@serverhostname/var/lib/git/myrepository.git
file:///var/lib/git/myrepository.git