5
5

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便利帳

5
Last updated at Posted at 2014-07-01

git repository作成

初期設定

git init --bare --shared

file名修正

file名修正

  • default branch設定

git symbolic-ref HEAD refs/heads/develop

git ログ周り##

ログ周り

  • get a file from a specific revision

git show commit_version:file_path

  • あるファイルの変更履歴

git log --name-only -p filename

  • 特定のソースコードの履歴

git log -p -S '文字列'

  • ログカスタマイズする

git config alias.logs "log --date=format:'%Y-%m-%d' --pretty=format:'%h %an(%ad):%s'"
git logs [--name-only] file そのコミットに変更したファイルリストも出てくる

  • List all the files for a commit in Git

git show --name-only commit_version

  • pushしたコミットを取り消す

git push -f origin HEAD^:master

  • 修正コミットコメントから検索

git log --grep xxxx --author xxxx

  • stash内容を覗く

git stash show -v

ファイル追加と削除

  • 削除

git rm $(git ls-files --deleted)
git rm git status | grep deleted | awk '{print $3}'
git status | awk '$2 == "deleted:" {print $3}'

参考:How to 'git rm' all deleted files shown by 'git status'

submodule

  • 追加

git submodule add git_repo local_path gitフォルダーに.gitmodulesが生成される

  • clone

git submodule initする前に確認できること
git submodule -hash-key submodule name(submoduleがまだregisterしていない)
.git/config submoduleに関しての情報がない(submoduleがまだregisterしていない)

  • submodule list

git ls-files --stage | grep 160000

  • 後悔する

git cherry-pick
http://te2u.hatenablog.jp/entry/2013/11/02/130740
git cherry-pick -m 1 SHA
マージされたやつをrevertされたので、そのコミットをもう一度コミットする

  • あるコミットから指定されたファイルを復元する

git checkout commit -- FILE_PATH でファイルが今いるブランチに復元されてステージされます。

  • submoduleのクロンいろいろ

git submodule update --init = git submodule init && git submodule update
git submodule --recursive = 素晴らしすぎる存在
git submodule foreach --recursive | tail -r | sed 's/Entering//' | xargs -I% cd % ; git add -A & git commit

参照資料:
Git Submodule功能
レポジトリにsubmoduleの追加
一括commit

branch

git remote show origin
git remote prune origin
Gitでリモートの共有リポジトリにあるブランチを消す時のメ

remote branch一括削除(master以外)

for b in `git ls-remote -h origin | cut -f2 | sed -e 's/refs\/heads\///' | grep -v 'master'`; do git push --delete origin $b; done;

local branch一括削除(master以外)

for b in `gbr | grep -v master`; do gbr -d $b; done

マージ

git stash popでコンクリフトした時の解決方法

gitツール

git自動更新

WORKSPACE=$(cd $(dirname $0)/../;pwd)

source ~/.bash_profile
cd $WORKSPACE
remote_sha=$(git ls-remote origin HEAD | cut -f1)
local_sha=$(git log -1 --pretty=format:%H)

# 変更がある時、ソースを更新する
if [ $remote_sha != $local_sha ]; then
-   git pull origin master
-   git submodule update --init
fi
5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?