以前のリビジョンの文書です
$ git clone https://github.com/git/git.git $ cd git $ make prefix=/usr/local all doc $ sudo make prefix=/usr/local install install-doc install-html
$ wget http://git-core.googlecode.com/files/git-1.7.9.4.tar.gz $ tar zxf git-1.7.9.4.tar.gz $ cd git-1.7.9.4 $ ./configure --prefix=$HOME/local $ gmake $ gmake install
portsからインストールする場合はgit-core
$ sudo port install git-core
$ cd my_project $ git init
$ git add . $ git commit -m "import"
add .ですべてのファイルを追加したあと、コミットしてます。
$ git checkout -b new_branch
$ git push origin new_branch
その後githubとかgitlabでnew pull requestかnew merge request
$ git pull $ git checkout -b pull_branch origin/pull_branch Branch pull_branch set up to track remote branch pull_branch from origin. #編集後 $ git commit -a -m "fix merge" $ git push origin pull_branch
その後github,gitlab上でqull request,merge requestボタンを押す。
$ git checkout master $ git fetch origin $ git merge origin/merge_branch $ git push origin master
$ git checkout -t origin/topic_branch
$ git branch -d delte_branch
ローカルのブランチ削除後、:(コロン)をつけてpush
$ git push origin :delte_branch
$ git push origin --tags
ファイルとコミットした情報を両方消す
$ git rm test.txt
$ git rm -r test_dir
ファイルは残したい場合
$ git rm --cached test.txt
最新のコミットまで戻す
$ git reset --hard HEAD
$ git stash -p
$ git merge <取り込みたいbranch>
コンフリクトした場合は
<<<<<<< 自分のブランチ ======= 取り込んだブランチ >>>>>>>
取り込んだブランチの変更を一括で優先したい場合
$ git merge --theirs
自分のブランチの変更を一括で優先したい場合
$ git merge --ours
giant_fileが、消したいファイル
$ git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch giant_file' --prune-empty --tag-name-filter cat -- --all $ git commit --amend -CHEAD $ git push
会社でやった作業を家でもやりたいな,管理はgitで。って時の方法を自分的手順まとめ。
サーバにsakuraインターネットを利用して、
ローカルはMac OS X Leopardでの場合です。
まず、さくらインターネットをリモートリポジトリとして使う場合は下記のようなエラーがでて動かないので
git-receive-pack: Command not found. fatal: The remote end hung up unexpectedly
解決方法として.chrcにgitのパスを通す必要があります。
set path=($path $HOME/local/bin )
できたら、
サーバ側でbareリポジトリを作る。bareリポジトリは作業ファイルがない管理情報だけのリポジトリ。あと、慣例でbareリポジトリとして使用するディレクトリには「.git」という拡張子をつけるんだそうです。
$ mkdir ~/work/test_project.git $ cd ~/work/test_project.git $ git --bare init
ローカルにgitリポジトリを作成する。
$ cd ~/work/test_project $ git init $ git add . $ git commit -m "import"
次にローカルのgitリポジトリに【sakura】という名前でリモートの情報を登録する。
$ git remote add sakura ssh://username@host/home/username/work/test_project.git
そしたらpushする
$ git push sakura master
これは【sakura】にbranch【master】をプッシュするって意味です。branch【master】は始めに作ったリポジトリのデフォルトです。
そのあと家とかで作業する場合cloneを使ってサーバからコピーする。
$ cd ~/work $ git clone ssh://username@host/home/username/work/test_project.git
そのままだとremoteが【origin】で登録されているので【sakura】に名前変更
$ git remote rename origin sakura
renameは古いgitだとできないっぽいです。Debian lennyのaptからインストールしたものだとだめでした。その場合は.git/configを直接編集で。
globalな無視するファイルというかignoreの設定。
$ git config --global --add core.excludesfile "$HOME/.gitignore"
そのあと~/.gitignoreファイルに無視したいファイルとかディレクトリを追加
#*# .#* .DS_Store .hg .svn
cloneやpullは誰でもできるようにgitプロトコルで、pushは限定するためにsshプロトコルからやるように。FreeBSDは6.4だけど別に他のバージョンでもLinuxでもそんなにかわんない。気がする。
まず、これのためだけのgitユーザーを作る。homeディレクトリは/home/gitであとはてきとうに。
$ adduser Username: git . . . Home directory [/home/git]: . .
gitリポジトリ用のディレクトリを作成
$ mkdir /home/git/repo
gitがなかったらgitをインストール
$ cd /usr/ports/devel/git $ make install clean
で、/etc/servicesにgitのサービスを追加
$ vi /etc/services git 9418/tcp
/etc/inetd.confに
$ vi /etc/inetd.conf git stream tcp nowait git /usr/local/libexec/git-core/git-daemon git-daemon --inetd --export-all --base-path=/home/git/repo
を追加。
やったことないけどたぶん、こうじゃないかと。
$ touch /etc/xinetd.d/git-daemon
$ vi /etc/xinetd.d/git-daemon service git { disable = no type = UNLISTED port = 9418 socket_type = stream wait = no user = git server = /usr/local/libexec/git-core/git-daemon server_args = --inetd --export-all --base-path=/home/git/repo log_on_failure += USERID }
一応ポートを制限したい。ので下記を追加。LANの中だけからアクセスできるように。
$ vi /etc/hosts.allow git-daemon : 192.168.1.0/255.255.255.0 : allow git-daemon : ALL : deny
FreeBSDはhosts.denyがなくて全部hosts.allowに書くルール?なのでallowとdenyの順番に注意。
上に書いてあるほうが優先順位が高くなるので一番上にある ALL : ALL : allowを消さない場合下に何書こうが全部通るので消したくない場合は一番上にgit-daemonを記述。
これで完了なので、再起動するか
$ kill -9 inetdのpid $ /usr/sbin/inetd -wW -C 60
でおーけー。
サーバ側。
gitは–bareで作成しなくちゃいけないようです。
$ cd /home/git/repo $ mkdir testproject.git $ cd testproject.git $ git --bare init $ touch git-daemon-export-ok $ chown -R git:git ../testproject.git
普通はgit-daemon-export-okというファイルを作らなきゃいけないそうなんですが、 git-daemonを–export-allで起動してるといらない気がします。
でローカル側。gitrepoの名前(適当です)でremoteの設定を追加してpush
$ cd ~/works/testproject $ git init $ git add . $ git commit -m "import" $ git remote add gitrepo ssh://git@remote.host/home/git/repo/testproject.git $ git push gitrepo master
$ git clone git://remote.host/home/git/repo/testproject.git ./testproject
使ってみた。
まずインストール
$ sudo gem install bananajour
バージョン直したりしてちょっとひっかかった。
バージョン指定でインストールする場合は –versionを使う。下のように。
$ sudo gem install rack --version '= 1.0.0'
で、見たいgitリポジトリのディレクトリに移動してaddする必要があります。
そのあとbananaレポジトリにプッシュ。
$ cd ~/works/myProject.git $ bananajour add $ git push banana master
あとはブラウザでhttp://localhost:9331/にアクセスすると見れます。
使っていく場合はcommitのあとbananaレポにpushしていきます。
$ git commit -m "fix" -a $ git push banana master