git的排错神器pickaxe和git blame

git log -Sstring 这里的-S选项被称作pickaxe,这是一个非常好的排错工具。

比如: git log -Sinclude –pretty=oneline –abbrev-commit init/version.c

会把减少了,或者增加了include的commit全部找出来。

要注意的是,如果有一个提交增加和减少include的次数一样,这个commit不会被列出来。

/////////////

另外一个排错工作是 git blame:

git blame可以用来帮助查找引入bug的commit。git blame告诉你谁,什么时候,是哪个commit更改了某个文件。

如: git blame -L 32, init/version.c

knowledge gained from learning git.

# If you inadvertently remove a file of your working copy. Don't worry. Git are good at recovering old versions of files, such as:
$git checkout HEAD — data

 

# show what the file looks like in a certain branch.
$git show branch_name:file_name

# In newer versions of Git, git diff –ours is a synonym for git diff HEAD, because it shows the differences between "our" version and the merged version. Similarly, git diff MERGE_HEAD can be written as git diff –theirs. You can use git diff –base to see the combined set of changes since the merge base, which would otherwise be rather awkwardly written as:
git diff $(git merge-base HEAD MERGE_HEAD)

# While you are in the process of resolving a conflict, you can use some special git log options to help you figure out exactly where the changes came from and why. Try this:
$git log –merge –left-right -p
–merge shows only commits related to files that produced a conflict.
–left-right displays < if the commit was from the "left" side of the merge("our version", the one you started with), or > if the commit was from the "right" side of the merge("their" version, the one you're merging in).
-p shows the commit message and the patch associated with each commit.

If your repository were more complicated and several files had conflicts, you could also provide the exact file names you are interested in as a command line option, like this:
$git log –merge –left-right -p hello

# The -s option to git ls-files shows all the files with all stages. If you want to see only conflicted files, use the -u option instead.

# $ git checkout -m branch_name
If possible or if specifically requested with the -m option, Git attempts to carry your local change into the new working directory by performing a merge operation between your local modifications and the target branch.

# $ git reset –hard ORIG_HEAD
If you want to abort or discard the merge after it has finished(that is,after it has introduced a new merge commit), use the above command. Prior to beginning the merge operation, Git saves your original branch HEAD in the ORIG_HEAD ref for just this sort of purpose.
You should be very careful here, though. If you did not start the merge with a clean working directory and index, you could geet in trouble and lose any uncommitted changes you have in your directory.

# Just show what the file looks like in a branch.
$ git show branch_name:file_name

# The command for manipulating remotes is git remote. This operation introduces a few new settings in the .git/config file.