S
S
Seeker2020-01-17 00:03:53
git
Seeker, 2020-01-17 00:03:53

How to perform some actions with commits in git?

I'm getting started with the git version control system. When working on my first project, the question arose whether it was possible to edit already made commits or not. Here is the sequence of actions I did in my project:

  1. created index.html and .htaccess file, made a commit
  2. created action.php file and changed index.html, made commit
  3. created index.php as an analogue of index.html, but already in the PHP language, also included the functionality from action.php (index.html and action.php were no longer needed), made a commit
  4. found an error in index.php, edited it, made a commit
  5. found out that deletion of index.html and action.php was not committed for me, I committed

Actually, I just can’t figure out how to do 2 things:
I consider the comment to commit 1 to be incorrectly informative and I want to rename it. I read on the Internet that only the current commit can be renamed, that is, first I need to checkout for commit 1, I do:
git checkout <хэш коммита 1>
git commit --amend -m "новый комментарий"

after these actions, when viewing the history through "git log" I see that all my commits are gone except for the changed one, and when viewing through "git log --all" I see that there are no longer 5, but 6
commits The second question is how to delete commits 3 and 4 so that they disappear from "git log --all", I actually had 3 changes in the project, commits 3 to 5 are essentially steps of one change and there is no need to store commits 3 and 4 in the history no.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-01-17
@jcmvbkbc

git rebase -i <commit id>
-- mark the commit as r (reword) in the rebase list.
It's not "delete", it's "merge with other commits".
-- mark all consecutive commits to be merged, except the first one, as s (squash) in the rebase list.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question