Skip to content

投稿

Git チートシート

2014年10月1日 • 2分で読める

Git チートシート

以下は私が何度も使用しているgitコマンドです。

リポジトリのクローン

git clone https://github.com/tinymce/tinymce-dist.git

既存のgitファイルをリモートgitリポジトリに追加

cd /path/to/my/repo
git remote add origin https://lostinkali@bitbucket.org/lostinkali/flightstats.git
git push -u origin --all # 初回時にリポジトリとその参照をプッシュ
git push -u origin --tags # タグをプッシュ

既存フォルダにリポジトリを作成

git init
git add .
# ローカルリポジトリのファイルを追加し、コミット用にステージング
git commit -m "Initial commit"

現在のブランチをmasterに変更

git checkout better_branch
git merge --strategy=ours master # このブランチの内容を保持しつつ、マージを記録
git checkout master
git merge better_branch

ブランチの削除

git branch -D bugfix

前のコミットに戻す

git checkout master
git reset --hard e3f1e37
git push --force origin master
# 確認のため(差分は出力されない)
git diff master..origin/master

ファイルをgitに追加

git add [filename]

ログの最新コミット以降の追跡されていないファイルを削除

git clean -fd

追加されたファイルをgitにコミット

git commit -m "enter message here"

gitからファイルを削除。変更がある場合でも強制的に削除するには-fを使用

git rm file1.txt

特定の時点にタグを付ける

git tag -a v1.4 -m 'my version 1.4'

著者:Chuck Conwayはソフトウェアエンジニアリングと生成AIを専門としています。ソーシャルメディアで彼とつながりましょう:X (@chuckconway) または YouTube をご覧ください。

↑ トップに戻る

こちらもおすすめ