0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

逆引きプログラマブルGit (WIP)

Last updated at Posted at 2017-11-17

ワークツリーにおける情報取得

  • 現在のブランチ名を取得
> git symbolic-ref --short HEAD
master

(git rev-parse --abbrev-ref HEADとかもあるけど、どれが最適?)

  • HEADのcommit idを取得
> git rev-parse HEAD
7c6a8d55d5a950ceab260499efb3038f86043fe1
  • ブランチ/タグ等の一覧
    git for-each-ref --format='%(refname)' PATTERN

    • ローカルブランチ一覧
      git for-each-ref --format='%(refname)' refs/heads
    • リモートブランチ一覧 (リモート名がoriginの場合)
      git for-each-ref --format='%(refname)' refs/remotes/origin
  • HEADのタグ名一覧を取得

> git tag --contains
test-tag1
test-tag2

(--contains--points-atの違いは?)

  • タグの有無をチェック
if git rev-parse "タグ名" >/dev/null 2>&1; then
  echo "指定のタグが有る"
else
  echo "指定のタグが無い"
fi

リモートリポジトリに関する情報取得

  • リモートのブランチ一覧
> git ls-remote URL
7c6a8d55d5a950ceab260499efb3038f86043fe1        HEAD
892061636bbb85dba1d265c6ac36d595d64eda17        refs/heads/develop
7c6a8d55d5a950ceab260499efb3038f86043fe1        refs/heads/master
668e2255d29e4078b1163f3132a353572037dfff        refs/tags/release-20171117_01

(ブランチ名のみは拾えない?)

  • リモート名に対応するURLの取得 (リモート名の設定有無にも使用可能)

git config remote.REMOTE_NAME.url

> git config remote.origin.url
https://github.com/vmi/selenese-runner-java.git
  • アップストリーム名の取得
> git rev-parse --abbrev-ref '@{upstream}'
origin/master

ローカルリポジトリの操作

  • ブランチをチェックアウトせずにリモートと同期する

git update-ref refs/heads/BRANCH_NAME refs/remotes/REMOTE_NAME/BRANCH_NAME

> git update-ref refs/heads/master refs/remotes/origin/master
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?