参考サイト

https://try.github.io/levels/1/challenges/1

新しいブランチを作ってコミットするまで

git checkout -b feature/mynewbranch
git push origin feature/mynewbranch -n
git push origin feature/mynewbranch

チェックアウト手順

クローンする

git clone http://example.com/git 任意のディレクトリ名
cd 任意のディレクトリ名

pullする

git pull origin testing

コマンド版 gitローカルリポジトリ作成

git init
git clone http://example.com/hoge/git.git [hoge以外の名前を付けたい場合]
git clone http://ID:PW@example.com/git

イメージ的には以下構成となる。

DIR/hoge/.git →http://example.com/hoge/git.git
DIR/fuga/.git →http://example.com/fuga/git.git
cd xxx
git branch -r
git branch 対象ブランチ
git checkout 対象ブランチ
#一度にやる場合は下記
git checkout -b 対象ブランチ
git remote -v
origin: レポジトリの場所(URL)の別名
master: ブランチの名前

デフォルトの対象はorigin/masterだ。

git config --list

上記コマンドで今どこを示しているかを確認せよ。

git pull origin ブランチ名称
git remote add NEW_REMOTE git@bitbucket.org:xxxx/foo.git

コマンド版を使う場合の設定

/.gitconfigに設定を保存しておける。

SVNとの違い

ローカルリポジトリ、index、リモートリポジトリと構成要素が複雑怪奇。ブランチがSVNより増える傾向がある。

addコミット準備領域であるindexに追加する
commitあくまでローカルリポジトリに対してのコミット。-aオプションをつけないと変更してもコミット対象にはならない
PUSHリモートリポジトリへのコミット。SVNでいうところのコミットと同義。リモートリポジトリがすっからかんの場合は git push -u origin master
FETCHSVNでいうところのアップデート(ローカルへのマージは行わない?)
PULLSVNでいうところのアップデート(ローカルへのマージまで行うFETCH+MERGE)
cloneチェックアウトだが、gitではブランチの切替に利用する
forkgithubの機能。cloneと似ているが、分散開発用に元の所有者に通知がいく。forkするという行為はオリジナルへの貢献を前提とする。
アップストリーム ブランチローカルに対して上流にあるブランチ。cloneした場合はclone元だが、指定もできる
branch -aリモート含むブランチ一覧の表示
branch -dブランチの削除。すっからかんじゃないと削除不可能
git log --pretty=oneline pom.xmlログを省略形の一行で表示。
git log --abbrev-commit pom.xmlコミットIDを省略系。一行で表示。

checkout

ローカルブランチを作成して、そこにリモートを紐つけ

git checkout -b local_branch origin/remote_branch

このあとgit fetchが必要。git pullと何が違うの?

push

引数なしのpushは非常に危険 http://dqn.sakusakutto.jp/2012/10/git_push.html

ブランチ指定してPUSHgit push --set-upstream origin testing
実際には実行しない(dry-run)git push -n

pull

リモートから取得する(fetch+merge)

git pull origin testingoriginリポジトリのtestingブランチを取り込む

元に戻す系

svnのように簡単ではない。svn revertはgit checkout file名

checkout ファイル名svn revert ファイル名
checkout .すべてのファイルのローカル変更を取消!
revertコミットを取り消す
resetある時点のコミット以降をすべて取り消す!

マージ

git checkout merged
git merge マージ元のブランチ

チェックアウトなど

ファイルの変更サイクル

  1. 変更
  2. add(ステージングにファイルが追加)
  3. commit(ここまではローカルリポジトリ)
  4. push(リモートリポジトリにコミット)

ブランチ運用

masterブランチを統合ブランチとして、リリース向けに運用する。トピックブランチは機能追加、バグ修正のタイミングで作成され、リリース前に統合ブランチにマージされる。 branch -aでリモート含むブランチ状況を確認しながら作業する。

git branch testingtestingブランチ追加
git checkout testingtestingブランチに切替

マージ

first-forwardマージ

分岐以降統合ブランチに変更がない場合、統合ブランチのコミット履歴はトピックブランチのコミット履歴とイコールになる。シンプルなので早送りマージと呼ばれる。ただしトピックブランチの履歴は残らないので、たとえfirst-forwardが可能であってもやらないほうがよい。

マージ

通常のマージ。統合とトピックブランチをマージしたというコミットが作成される。

rebase

ブランチの履歴を消してマージ。トピックブランチが小さいものが多く、頻発するのであればこちらの運用が良いかもしれぬ。

特定のコミットのみマージ

git cherry-pick 5d0b85e02f5ae4c4984fac388015fe5ce1918673
git cherry-pick 1ea6be61498f49f00cfd0fd5a0a08590087930a6

いろいろためした

$ git status
On branch MyBranche
Your branch is up-to-date with 'origin/NewBranch'.
nothing to commit, working directory clean
$ git status
On branch development
Your branch is behind 'origin/Develop' by 6 commits, and can be  fast-forwarded.
 (use "git pull" to update your local branch)
nothing to commit, working directory clean

トラブルシューティング

error: failed to push some refs to 'http://example.com/git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

Install

It's easy to install from source! just configure and make and make install!

apache

git-http-backendがソースコンパイルだとないため、下記はバイナリーインストールのときのみ可能。

http://www.proton.jp/main/programming/git/smart-http.html

SetEnv GIT_PROJECT_ROOT /usr/local/git
SetEnv GIT_HTTP_EXPORT_ALL
 
ScriptAlias /git/ /usr/local/libexec/git-core/git-http-backend/
 
<locationMatch "/git">
   AuthType Basic
   AuthName "Git Area"
   AuthUserFile /usr/local/apache2/htdocs/.htpasswd
   require valid-user
   Order allow,deny
   Allow from all
</locationMatch>

gitstatsの使い方

まずはgitをクローンする。そのうえで以下のように実行するとoutput_dirにhtmlが出力される。

gitstats git_clone_dir/ /var/www/html/new_dir
gitstats -c commit_begin=ハッシュ(短いのでもOK)

http://manpages.ubuntu.com/manpages/trusty/man1/gitstats.1.html

httpとの連携

http://int128.hatenablog.com/entry/20130118/1358440428


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS