If the commit you want to fix isn’t the most recent one:
-
git rebase --interactive $parent_of_flawed_commit
If you want to fix several flawed commits, pass the parent of the oldest one of them.
-
An editor will come up, with a list of all commits since the one you gave.
- Change
pick
to reword
(or on old versions of Git, to edit
) in front of any commits you want to fix. - Once you save, git will replay the listed commits.
-
Git will drop back you into your editor for every commit you said you want to reword, and into the shell for every commit you wanted to edit. If you’re in the shell:
- Change the commit in any way you like.
git commit --amend
git rebase --continue
Most of this sequence will be explained to you by the output of the various commands as you go. It’s very easy, you don’t need to memorise it – just remember that git rebase --interactive
lets you correct commits no matter how long ago they were.
Today, when I try to push some code to the remote, it told me the there is a permission issue, I finally fixed it by created a new key, add it to my git account and local account. Here is the process of adding to local
$ git push -u origin master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
$ ssh -vT git@github.com
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: Connection established.
debug1: No more authentication methods to try.
Permission denied (publickey).
$ ssh-add -l
Could not open a connection to your authentication agent.
$ eval `ssh-agent`
Agent pid 4968
If you did not have a key, generate one according this https://help.github.com/articles/generating-ssh-keys
then add the key
$ ssh-add /c/Users/li/.ssh/key
Identity added: /c/Users/li/.ssh/key
$ ssh -vT git@github.com
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: Connection established.
debug1: identity file /c/Users/li/.ssh/identity type -1
Hi ***! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.3 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 1
$ git push -u origin master
Counting objects: 46, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (42/42), done.
Writing objects: 100% (46/46), 21.33 KiB, done.
Total 46 (delta 1), reused 0 (delta 0)
Create a new repository in a new directory via the following commands.
# Switch to home
cd ~
# Make new directory
mkdir repo02
# Switch to new directory
cd ~/repo02
# Clone
git clone ../remote-repository.git .