- 投稿日:2019-08-27T23:52:03+09:00
'git st'が遅いときの対処方法 -- Windows版 --
TL;DR
Windows版では、gitのaliasを使っていると展開に時間がかかることがあります。
shellのaliasを使いましょう。'git status'は打ちにくい
入力補完では候補が複数あって絞りきれません。
$ git sta stage stash statusaliasを使おう
.gitconfigのにaliasを設定します。~/.gitconfig[alias] st = statusなんか遅い
// @todo サンプルプロジェクトでGIT_TRACEした結果を貼る
gitの問題ではない
巨大なリポジトリに対するgitの速度問題への対応策として、
git gcなどがありますが、git status自体が遅いわけではないので、今回は当てはまらないようです。Windows版のgitでは、Windowsプロセスとgitとの橋渡し部分がネックになりやすいという記事を見つけました。
どうやら今回の原因もこれっぽいです。https://stackoverflow.com/questions/36925695/git-alias-slower-than-original-command
bashの関数を使う
gitのaliasを使うと遅いということで、bashにaliasを設定する方向で考えます。
普通にbashのaliasを使おうとするとスペースが使えないので、gitのaliasとは使用感が違ってきます。
その場合、bashの関数を使うことで同じ使用感でコマンドのレスポンスを向上できます。func_git() { if [ $1 == "st" ]; then command git status "${@:2}" else command git "$@" fi } alias git=func_git
- 投稿日:2019-08-27T20:53:41+09:00
fatal: refusing to merge unrelated historiesの対処法
fatal: refusing to merge unrelated historiesが出た場合、
git merge もしく git pull に
--allow-unrelated-histories 追記すれば解決
git merge --allow-unrelated-histories
- 投稿日:2019-08-27T19:40:20+09:00
macでゼロからgit 第六回 (push remote)
- 投稿日:2019-08-27T19:40:20+09:00
macでゼロからgit 第六回 (push remote clone)
- 投稿日:2019-08-27T19:16:07+09:00
macでゼロからgit第五回 (rm checkout)
When you remove a file in repository
$ rm 2.txt $ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: 2.txtIf you want to remove this file in version repository
git rm/add [file]
git commit -m "remove the file"If you don't want to remove this file in version repository
git checkout --2.txt
- 投稿日:2019-08-27T18:31:24+09:00
macでゼロからgit第四回 (checkout reset HEAD)
git commit -m "added new file"1.編集をwork directoryに戻す(Not added)
// use "git checkout -- <file>..." to discard changes in working directory $ git checkout -- readme.txt2.編集をwork directoryに戻す(Has added)
$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: LISENCE.txt $ git reset head LISENCE.txt $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: LISENCE.txt $ git checkout -- LISENCE.txt
- 投稿日:2019-08-27T17:40:52+09:00
macでゼロからgit第三回 (log reset reflog)
1. 以前提出したlogを見る
$ git log --pretty=oneline 9882f244353fcb2c6cc42226f620b3e119a9feb7 (HEAD -> master) added 2.txt efb01bb70f725652bfb85e9583ea1613ee7a616d added GPL 6af2b6cfa33b108c7acbbc530b17abf8456540eb add distributed 561e61e5bf4d545378d749a5ceb6834b2507a670 wrote a readme file561e61e5bf4d545378d749a5ceb6834b2507a670 is the commit id
wrote a readme file is the commit message
HEAD is the pointer which points to the current commit2. 今のversionから前へ戻る
// $ git reset --hard [commit id] $ git reset --hard efb01 HEAD is now at efb01bb added GPL3. これから全部出たcommit idを見る
$ git reflog efb01bb (HEAD -> master) HEAD@{0}: reset: moving to efb01 9882f24 HEAD@{1}: reset: moving to 9882 561e61e HEAD@{2}: reset: moving to 561e 9882f24 HEAD@{3}: reset: moving to 9882 efb01bb (HEAD -> master) HEAD@{4}: reset: moving to head^ 9882f24 HEAD@{5}: commit: added 2.txt
- 投稿日:2019-08-27T17:40:52+09:00
macでゼロからgit第三回 (log reset --hard reflog)
1. 以前提出したlogを見る
$ git log --pretty=oneline 9882f244353fcb2c6cc42226f620b3e119a9feb7 (HEAD -> master) added 2.txt efb01bb70f725652bfb85e9583ea1613ee7a616d added GPL 6af2b6cfa33b108c7acbbc530b17abf8456540eb add distributed 561e61e5bf4d545378d749a5ceb6834b2507a670 wrote a readme file561e61e5bf4d545378d749a5ceb6834b2507a670 is the commit id
wrote a readme file is the commit message
HEAD is the pointer which points to the current commit2. 今のversionから前へ戻る
// $ git reset --hard [commit id] $ git reset --hard efb01 HEAD is now at efb01bb added GPL3. これから全部出たcommit idを見る
$ git reflog efb01bb (HEAD -> master) HEAD@{0}: reset: moving to efb01 9882f24 HEAD@{1}: reset: moving to 9882 561e61e HEAD@{2}: reset: moving to 561e 9882f24 HEAD@{3}: reset: moving to 9882 efb01bb (HEAD -> master) HEAD@{4}: reset: moving to head^ 9882f24 HEAD@{5}: commit: added 2.txt
- 投稿日:2019-08-27T16:52:59+09:00
macでゼロからgit第二回 (status diff)
1. modify the readme.txt
$ vim readme.txtmodify the file:
Git is a 'distributed' version control system.
Git is free software.
2. see the git repository's status
$ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)3. the file has been changed, using diff to confirm which modified
$ git diff readme.txt diff --git a/readme.txt b/readme.txt index 46d49bf..9247db6 100644 --- a/readme.txt +++ b/readme.txt @@ -1,2 +1,2 @@ -Git is a version control system. +Git is a distributed version control system. Git is free software.4. 見直しfileがrepositoryに加える
git add read.txt5. commit file
$ git commit -m "added distributed" [master 6af2b6c] add distributed 1 file changed, 2 insertions(+), 2 deletions(-)6. after commit, working tree clean
$ git status On branch master nothing to commit, working tree clean
- 投稿日:2019-08-27T16:34:10+09:00
macでゼロからgit 第一回 (init, add, commit)
[TOC]
1. make a new directory
$ mkdir learngit $ cd learngit $ pwd2. set 'learngit' directory as a git repository
$ git init3. write a text file in this repository
$ vim readme.txtin vim, write this 2 lines:
Git is a version control system.
Git is free software.
退出:wq4. add the file to the git repository
git add readme.txt5. commit the file to the git repository
git commit -m 'wrote a readme file'
- 投稿日:2019-08-27T16:34:10+09:00
macでゼロからgit 第一回 (init, add, commit)
1. make a new directory
$ mkdir learngit $ cd learngit $ pwd2. set 'learngit' directory as a git repository
$ git init3. write a text file in this repository
$ vim readme.txtin vim, write this 2 lines:
Git is a version control system.
Git is free software.
退出:wq4. add the file to the git repository
git add readme.txt5. commit the file to the git repository
git commit -m 'wrote a readme file'
- 投稿日:2019-08-27T12:27:46+09:00
GitとGitHubの用語集(初心者向け)
gitの単語がわからなくなりがちだったのでひとまとめしました。
clone:クローン
リモートリポジトリ(外部サーバーなどにあるリポジトリ)を自分の手元の指定した場所にコピーする
init:イニット
リポジトリの新規作成、初期化など
git addする前にしたりする。間違って2回実行しても問題ないらしいadd:アド
作業ツリーにあるファイルの更新内容をインデックス(コミットする前に更新内容の一時的な保存をする場所、ステージ)に反映するためのgitコマンド
→ githubにアップする場合git add .ですべてのファイルと変更をステージング領域に追加されるcommit message:コミットメッセージ
コミットした内容や変更点などを書いていく。あとでなにを更新したかわからなくなりがちなのでわかりやすく書いた方がよさそうです。
→ githubにアップする場合git commit -m "ここにcommit message"で反映されるpush:プッシュ
ローカルのリポジトリの内容をリモートのリポジトリに送り込むコマンドです。
pushしないと変更した内容は自分の環境以外だとみれない。
→ githubにアップする場合git push "ブランチ名"merge:マージ
加えた変更を取り込む
pull:プル
リモートリポジトリの履歴を取得することができる。
pullした場合は自動的にmergeされる。
pullとはfetch:フェッチ
リモートリポジトリの内容を確認したいだけでマージをしたくない場合はfetchする
fetchとはconflict:コンフリクト
同じファイルの同じ場所を変更した場合に起こる。
解決方法は①手動でいっこずつ確認してどちらの変更を取り込むか確認する
②片方の変更を破棄するなど…(Hunkを戻すで一気に前回のコミットまでもどれます)stash:スタッシュ
今の作業を一時中断して別のブランチに移動するときなどに一時退避できる機能
checkout:チェックアウト
ブランチを切り替えたいときに使用するコマンド
いま作業しているブランチを出て、他のブランチで作業する場合に使用cherry-pick:チェリーピック
マージはすべてのコミットが取り込まれるのに対し、チェリーピックは選択したコミットのみ取り込む。
名前がかわいいgithubにあるもの編
![]()
fork:フォーク
こういうの↓
githubの機能では他の開発者のリポジトリをgithub上でclone(クローン)する。
git cloneと違うところは開発者への貢献が前提となる
開発者への通知がいきます
>fork する意味Watch:ウォッチ
twitterのフォローみたいな機能のようです。
新しく作成されたプルリクエストなどの通知を受け取ることができます。 特定のリポジトリの通知を受け取る必要がなくなった場合は、そのリポジトリの Watch を解除できますとのこと。
リポジトリの Watch と Watch 解除star:スター
いいね!機能のようなもの
starが多いと人気プロジェクトや注目プロジェクトということになるようです。
海外就職に有利になるとか…??まだまだあったのですがたくさんありすぎたのでこのくらいで…
- 投稿日:2019-08-27T12:15:57+09:00
[もう大丈夫]git コミットを消したあなたへ
git reset --hard ハッシュ値で特定のコミットまで戻る。
git reflogshimizu@MyComputer1:/mnt/c/Users/81905/Desktop/chatplus$ git reflog 1857c8dfb (HEAD -> netseeds3_lang_change) HEAD@{0}: reset: moving to 1857c8dfb60fbacd25e1b34658775d1af7f4f063 2d7f571e6 HEAD@{1}: checkout: moving from netseeds3_text_change to netseeds3_lang_change c85462328 HEAD@{2}: checkout: moving from netseeds3_lang_change to netseeds3_text_change 2d7f571e6 HEAD@{3}: checkout: moving from netseeds3_text_change to netseeds3_lang_change c85462328 HEAD@{4}: checkout: moving from netseeds3_lang_change to netseeds3_text_change 2d7f571e6 HEAD@{5}: checkout: moving from netseeds3_text_change to netseeds3_lang_change c85462328 HEAD@{6}: checkout: moving from netseeds3_lang_change to netseeds3_text_change
HEAD@{xx}というのは、過去何番目のHEADの状態を表す。
元に戻りたいポイントが分かれば、あとは、git reset --hardで強制的に巻き戻します。git reset --hard HEAD{1}
