Amending commits

One frequently used feature of Git is the ability to amend to a commit. This is possible because, in Git, there is a difference between creating and publishing a commit. This won't inconvenience users compared to CVS, where it would. If you make a typo in your commit message in Git, you can use git commit --amend to correct it. It's also technically possible in CVS, but it would be hard to implement:

 $ echo "This is the last line FOR REAL" >> README.md
$ git log
commit 499beb6dd81ee62e90b05ee8e9aa3ccced7a4fd2 (HEAD -> new-readme)
Author: Joost Evertse <[email protected]>
Date: Thu Dec 6 21:18:32 2018 +0100

A new line was added

Let's pretend I forgot to add something to my README.md file (a text file in my repository). The following code shows you how to add it to the last commit:

 $ echo "This is the last line FOR REAL" >> README.md
$ git add README.md
$ git commit -m "A new line was added FOR REAL" --amend
$ git log
commit 9c527dfe0ac2ce04b6cd1be6085bac00c7f31e6c (HEAD -> new-readme)
Author: Joost Evertse <[email protected]>
Date: Thu Dec 6 21:18:32 2018 +0100

A new line was added FOR REAL

By doing this, you can add to a commit, but this is only reflected in your local Git copy. You still have to push your changes to remote servers if you want others to see your changes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.31.159