Flight rules for Git

https://github.com/k88hudson/git-flight-rules 阅读后摘抄不熟悉的地方(还有很多没看…)

Repositories

I set the wrong remote repository

There are a few possible problems here:

If you cloned the wrong repository, simply delete the directory created after running git clone and clone the correct repository.

If you set the wrong repository as the origin of an existing local repository, change the URL of your origin by running:

1
$ git remote set-url origin [url of the actual repo]

For more, see this StackOverflow topic.

I want to add code to someone else’s repository

https://github.com/k88hudson/git-flight-rules#i-want-to-add-code-to-someone-elses-repository

Editing Commits

What did I just commit?

Let’s say that you just blindly committed changes with git commit -a and you’re not sure what the actual content of the commit you just made was. You can show the latest commit on your current HEAD with:

1
(master)$ git show

Or

1
$ git log -n1 -p

If you want to see a file at a specific commit, you can also do this (where <commitid> is the commit you’re interested in):

1
$ git show <commitid>:filename

I wrote the wrong thing in a commit message

If you wrote the wrong thing and the commit has not yet been pushed, you can do the following to change the commit message without changing the changes in the commit:

1
$ git commit --amend --only

This will open your default text editor, where you can edit the message. On the other hand, you can do this all in one command:

1
$ git commit --amend --only -m 'xxxxxxx'

If you have already pushed the message, you can amend the commit and force push, but this is not recommended.