20210913のGitに関する記事は4件です。

Git コマンド(メモ)

Gitコマンド一覧 ローカルリポジトリ作成 $ git init 変更分を全てをステージする(指定も可) $ git add . $ git add ファイル名 変更を記録する(コミット)(変更、削除、新規作成、複数ファイルの変更内容) $ git commit -m 'コミットメーセージ' 一つ前のコミットをやりなおす(※プッシュしていないもの) $ git commit --amend リモートリポジトリを新規追加する $ git remote add origin(リモートリポジトリ名)git@~ プッシュする(リモートリポジトリをGitHubに送る) $ git push origin ローカルブランチ名 現在の状況を確認する(変更、削除、新規作成、複数ファイルの変更内容) $ git status git addする前の変更分 $ git diff 変更履歴を確認する $ git log 履歴を一行で表示(見やすい) $ git log --oneline リポジトリをコピーする $ git clone リポジトリ名 ファイルを削除を記録 $ git rm ファイル名 $ git rm -r ディレクトリ名 ファイルへの変更を取り消す $ git checkout ファイル名 $ git checkout ディレクトリ名 $ git checkout . ステージした変更を取り消す(ワークツリーのファイルには影響なし) $ git reset HEAD ファイル名 $ git reset HEAD ディレクトリ名 $ git reset HEAD . ブランチ ブランチを新規作成する $ git branch ブランチ名 ブランチ一覧を表示 $ git branch ブランチを切り替える $ git checkout ブランチ名 変更履歴をマージする $ git merge ブランチ名 ブランチを変更する $ git branch -m ブランチ名 ブランチを削除する $ git branch -d ブランチ名 リモート リモートを表示する $ git remote リモートから情報を取得する(フェッチ) $ git fetch リモート名 リモートから情報を取得してマージする(プル) $ git pull  # これと同じ $ git fetch origin リモート名 $ git merge origin リモート名 リモート変更 $ git remote rename 旧リモート 新リモート リモート削除 $ git remote rm リモート名 リモートの詳細情報を表示 $ git remote show リモート名
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【Git】変更履歴確認方法

ファイルの「行単位」の変更コミットIDを確認 # 行単位のコミットIDを確認可能 $ git blame <ファイル名> 「コミット単位」の変更履歴を確認 # 最新のコミットの詳細を表示する $ git show # 指定したコミットの詳細を表示する $ git show <コミットのハッシュ値>
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

gitでエラーメモ書き Windows

いつもと違うPCのときに遭遇したエラー git push リモートリポジトリ名 master fatal: 'リモートリポジトリ名' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. リモートリポジトリの指定 git remote add リモートリポジトリ名 リモートリポジトリのURL 公開鍵を作成 ssh-keygen -t rsa -C "アカウントのメールアドレス" Generating public/private rsa key pair. Enter file in which to save the key (/Users/PCユーザー名/.ssh/id_rsa): /Users/PCユーザー名/.ssh/鍵の名前(なんでもOK) Enter passphrase (empty for no passphrase):"パスを入力" Enter same passphrase again:"パスを再入力" Your identification has been saved in /Users/PCユーザー名/.ssh/鍵の名前. Your public key has been saved in /Users/PCユーザー名/.ssh/鍵の名前.pub. The key fingerprint is: 以下省略 作成した公開鍵の中身をコピー(Windows) clip < ~/.ssh/鍵の名前.pub github上で登録 使用したいレポジトリ>Settings>Deploykeys Title:任意 Key:コピーした公開鍵の中身を張り付ける Add keyを押す git bashでpush git push リモートリポジトリ名 master (うまくいかなかったら-fオプションで強制的にpush) gut push時に遭遇した(error: 403) remote: Permission to ユーザ名/リポジトリ名.git denied to fatal: unable to access 'https://github.com/ユーザ名/リポジトリ名.git/': The requested URL returned error: 403 URLにユーザ名 git remote set-url origin https://<ユーザ名>@github.com/<ユーザ名>/<リポジトリ名>.git gut commit時に遭遇した git commit -m 'first commit' error: pathspec 'commit'' did not match any file(s) known to git ダブルクォーテーションで git commit -m "first commit" そのほか困ったら git status git log git show git remote
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

git clone --depth 1 したリポジトリの履歴をやっぱりすべて取得する

ビルドで過去のコミット数を参照している部分があり、--depth 1でクローンしたリポジトリのすべての履歴が後から必要になりました。 以下のコマンドですべての過去のコミット数が取得できるようになりました。 git fetch --unshallow 参考 https://stackoverflow.com/questions/6802145/how-to-convert-a-git-shallow-clone-to-a-full-clone
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む