How do I edit an incorrect commit message in Git?

From: http://stackoverflow.com/questions/179123/how-do-i-edit-an-incorrect-commit-message-in-git

git commit –amend -m “New commit message"

Used to amend the tip of the current branch. Prepare the tree object you would want to replace the latest commit as usual (this includes the usual -i/-o and explicit paths), and the commit log editor is seeded with the commit message from the tip of the current branch. The commit you create replaces the current tip — if it was a merge, it will have the parents of the current tip as parents — so the current top commit is discarded.

It is a rough equivalent for:

$ git reset –soft HEAD^
$ … do something else to come up with the right tree …
$ git commit -c ORIG_HEAD
but can be used to amend a merge commit.

廣告

How can I uncommit the last commit in a git bare repository?

From: http://stackoverflow.com/questions/4624881/how-can-i-uncommit-the-last-commit-in-a-git-bare-repository

You can use the git update-ref command. To remove the last commit, you would use:

$ git update-ref HEAD HEAD^
Or if you’re not in the branch from which you cant to remove the last commit:

$ git update-ref refs/heads/branch-name branch-name^
You could also pass a sha1 if you want:

$ git update-ref refs/heads/branch-name a12d48e2
See the documentation of the git-update-ref command.

Windows 安裝 cygwin + git package 解決中文亂碼問題

之前在 Windows上使用 Git 都是安裝 msysgit 或 git for windows ,但安裝更新為較新版的 Git for Windows 時,卻發生與使用之前的版本的 Git 建立的程式專案不相容問題。而且需要將舊專案UPGRADE到新版本的Git上。雖然新版1.7.10以上的Git 核心支援 Unicode,但是在 Bash 下無法輸入非  ASCII 的字元是一大問題(請參考下面兩段敘述)。

因此我變心了,改投 cygwin+git 的懷抱。在cygwin的操作環境下,安裝 git 套件 的確獲得較佳的 Unicode 編碼支援。不會在有中文輸入及顯示的問題發生在 git 的使用上。

from: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support

Git for Windows Unicode Support
As of V1.7.10, Git for Windows supports Unicode. Most importantly, this means that Git repositories with non-ASCII file names can now be seamlessly shared between Git for Windows and other Git flavors (i.e. Git on Linux/Mac, Cygwin-Git and JGit / EGit).

Unfortunately, it also means that users of previous Git for Windows versions need to update their Git settings, and probably need to migrate their Git repositories, too.

Known Issues Git for Windows

MSYS programs don’t fully support Unicode yet, e.g.
bash doesn’t let you type non-ASCII characters
ls converts non-ASCII characters to ‘?’ when printing to the console (redirecting to a file or another program works, though)
Tcl only supports BMP (Basic Multilingual Plane, i.e. Unicode characters \u0000 – \uffff), therefore gitk and git-gui currently don’t support e.g. CJK Extensions B – D.

MINTTY 可以在windows 作業系統上運行非常不錯的console

為什麼會對它有興趣是因為windows自帶的console實在有點難用。當在查看git log 時,小小的作業視窗並且無法自由自在的調整視窗大小。

下面這篇是對mintty非用不可的理由說明:
9 Reasons Why MinTTY is the Best Terminal on Windows

官方也對它的特性做了以下的描述

  • Xterm-compatible terminal emulation.
  • Native Windows user interface with a simple options dialog.
  • Easy copy & paste.
  • Drag & drop of text, files and folders.
  • Ability to open files and URLs with Ctrl+click.
  • Comprehensive character encoding support, including UTF-8.
  • Wide character display and Windows IME support.
  • Window transparency, including glass effect on Vista and 7.
  • 256 colours.
  • Fullscreen mode.
  • Options stored in a text file. No registry entries.
  • Small program size and quick scrolling.

因為mintty 是基於putty0.6.0 的原碼設計的,所以用過putty的人可以不難想像它可帶來什麼方便之處。
繼續閱讀

Windows GIT 解決中文顯示亂碼問題

終端機內無法輸入中文:

修改「C:\Program Files\Git\etc\inputrc」

#disable/enable 8bit input
set meta-flag on
set input-meta on
set output-meta on
set convert-meta off

ls 無法顯示中文目錄:

修改「C:\Program Files\Git\etc\profile」

#修正 ls 無法顯示中文目錄,新增下面這行
alias ls='ls --show-control-chars --color=auto'
#如果安裝的msysGit此設定已成預設值(bash_profile設定檔裏)

git log 無法顯示中文註解:

繼續閱讀