gitでうっかりファイルを上書きしてコミット、昔の変更が飛んでしまった..ときの修正ファイルの戻し方
git logとかtigとかgithubとかbitbucketとかお使いのもので、ハッシュを調べます
$ git log /path/to/file
とかで 791d6ce を調べて
$ glt checkout 791d6ce /path/to/file
これでstagingに戻ります
(git add された状態)
gitでうっかりファイルを上書きしてコミット、昔の変更が飛んでしまった..ときの修正ファイルの戻し方
git logとかtigとかgithubとかbitbucketとかお使いのもので、ハッシュを調べます
$ git log /path/to/file
とかで 791d6ce を調べて
$ glt checkout 791d6ce /path/to/file
これでstagingに戻ります
(git add された状態)
gitで管理してるディレクトリに大量にファイルをしてしまった..
$ git status
On branch v.2.13.3
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: data/Smarty/templates/default/abouts/index.tpl
modified: data/Smarty/templates/default/cart/index.tpl
modified: data/Smarty/templates/default/contact/complete.tpl
modified: data/Smarty/templates/default/contact/confirm.tpl
modified: data/Smarty/templates/default/contact/index.tpl
modified: data/Smarty/templates/default/entry/complete.tpl
modified: data/Smarty/templates/default/entry/confirm.tpl
modified: data/Smarty/templates/default/entry/index.tpl
modified: data/Smarty/templates/default/entry/kiyaku.tpl
modified: data/Smarty/templates/default/error.tpl
modified: data/Smarty/templates/default/footer.tpl
# 延々に続く..
となったときに全て無かったことにするには
$ git clean -f
これで元通り
あ、すべて消えるのでご使用はお気をつけてください
CakephpのbeforeFilterでComponentを使っているとなんやらメソッドがないとかエラーが
Fatal error: Call to a member function save() on a non-object ...
えー、普通に使ってるのに..と思ったら、beforeFilterでは、Componentのstartupがまだ呼ばれてないっぽい(使える準備ができてない)
仕方ないので、メインのメソッドに書きました
このブログもWordpressを使っていますが
シンタックスハイライト(プログラムコードとかを綺麗に見せる)に
というプラグインを使っていましたが、Markdown形式でかける
のソース表示でいいか、と思ったのと、コードのタグとかがサニタイズ( < が < にみたいに変換されたりするので外すことに
プラグインを外すと
[text]
シンタックスハイライトしていた文章..
[/text]
[php]
シンタックスハイライトしていたphpのコード..
[/php]
と文章に SyntaxHighlighter Evolved で使っていた、記号が出てしまいます
Jetpack by WordPress.comのMakdownは ``` で囲えばいいのですがこれは
preタグ+codeタグに変換されます
文章をMysqlでいっきに置換してみます
まず [text] とか出てる記事を見て ID を調べます
http://(wordpress address)/?p=611
とかの611がIDだったりします
ひとつ試しにIDを指定して置換
サーバー、mysqlにログイン
$ mysql -u (mysqluser) -p (wordpress database name)
表示した記事の文章を置換して [text] -> <pre><code> に変換
mysql> update wp_posts set post_content = replace(post_content, ‘[text]’, ‘<pre><code>’) where id = 611;
mysql> update wp_posts set post_content = replace(post_content, ‘[/text]’, ‘</code></pre>’) where id = 611;
記事確認
http://(wordpress address)/?p=611
無事きれいになってたら成功
where以降をとってしまえば、全記事に適用されます([text]がない記事には影響しない)
mysql> update wp_posts set post_content = replace(post_content, ‘[text]’, ‘<pre><code>’);
mysql> update wp_posts set post_content = replace(post_content, ‘[/text]’, ‘</code></pre>’);
どうように [php] も取ります
mysql> update wp_posts set post_content = replace(post_content, ‘[php]’, ‘<pre><code>’);
mysql> update wp_posts set post_content = replace(post_content, ‘[/php]’, ‘</code></pre>’);
ひとつプラグインが減ってすっきりしました