Pagine

Thursday 1 June 2017

How to edit a commit with git

It is possible three actions to edit a commit:
  1. Change the comment;
  2. Add one or more files in a commit;
  3. Remove one or more files in a commit.

Examples

1) If you want to edit the description of your last commit, use the following line: 
 $ git commit --amend
2) Let's suppose that your last commit contains buggy code; you can specify that your changes on the file are part of the last commit:
 $ git add file.txt
 $ git commit -v -amend
3) Now I want to remove a file I included accidentally in the last commit (because this file deserves a new commit):
 $ git reset HEAD^1 file.txt
 $ git commit --amend -v
 $ git commit -v file.txt

No comments:

Post a Comment