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?

git 学習中

Last updated at Posted at 2019-11-30

#まとめて git pull したいときは

$ find . -name .git -printf '%h\n' | xargs -I{} sh -c 'cd {}; git pull;'

これをaliasにでも登録しておけば、OK

もう少しスマートな方法が分かれば、更新します。

#checkoutをすべて破棄したい

$ git checkout master
$ git status

壊しちゃった

特定のSHAに戻して、何事もなかったことにしたい

git push -f origin <SHA#>:<Branch Name>

自分のローカルブランチなら、簡単です。メインブランチなど重要なものは管理者でロックされている可能性はあります。そうなると、本コマンドは実行できません。

そうなる前に

なにをcommitするか、確認しましょう

git ls-files -m

変更対象のファイルが表示されます。注意事項は、自分のディレクトリ以下の情報しか表示しません。全体を表示したければ、gitのルートディレクトリまで移動してから実行しましょう。
"-m"は、modify。変更したファイルを表示してくれます。

過去commitをまっさらにする

過去commitをまっさらにするには、次の手順で進めます。平たく言うと、次の手順です。

  • 新しくブランチを設定
  • そこに、master/mainブランチを移動
  • (option) github/gitlab側から、デフォルトの設定を変更
$ git checkout --orphan main
$ git add -A
$ git commit -m "The first commit"
$ git push origin main
$ git branch -D master
(GUIからデフォルトの設定とブランチの削除)

普通の人は使わないと思います。

直前のcommitをまっさらにする

pushしようと思って、準備をしたが、

$ git reset --soft HEAD^    (commit状態からadd状態へ戻す。git statusでadd/new表示される)
$ git reset HEAD .          (add状態を解除する)

Remote Branchを削除する

もう使わないリモートブランチを根こそぎ削除

$ git push origin --delete (branch name)

おしまい

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?