Reputation: 561
I have spent a long time reading and trying to figure out git commit --amend, but I still do not understand how the # are used in the editmsg.
I am worried to edit this without knowing what I am doing because I have read that git commit --amend only does the most recent commit,and once I save and exit , it will be counted as a new commit.
I have accidentally committed and pushed (but the push failed) some large files. But I have also written scripts that were supposed to be pushed from the same commit as the large files.
I am trying to delete the lines with the large files in the new commit , but I don't understand how to do this.
This is my commit file below, but I don't understadn if I should delete the lines with the # (I tried this but it didn't work , and the git log is the same ):
the commit message of the one I want to change is here but I don't want to just change the message, I want to delete the large files in the commit so that the push works.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Thu Feb 8 18:30:32 2018 -0900
#
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# new file: script.py
# new file: super_large_file.npy <--- I deleted this line but it appeared again, it is becuase deleting a line with # is ignored? Do I just rewrite the stuff after the # lines?
My question is , why does deleting the line of the large file (including the # ) not work and the commit remains still wanting to push the large file?
Should I just rewrite the commit file without the # ? But I also read that git takes away the # , so I am confused
Upvotes: 1
Views: 18847
Reputation: 1327334
First, those are comments: removing a line starting with #
has no effect in your git repository content.
They include hints and the list of files included with the commit.
I would recommend, in order to actually remove that file from your repo history, to use the new git filter-repo
which replaces BFG and git filter-branch
.
Note: if you get the following error message when running the above-mentioned commands:
Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`
it means you have to update git
.
First: do that one copy of your local repo (a new clone)
See "Path based filtering":
git filter-repo --path file-to-remove --invert-paths
At the end, you can (if you are the only one working on that repository) do a git push --force
Second, the hints displayed in a commit messages are changing with with Git 2.25.1 (Feb. 2020): "git commit
" gives output similar to "git status
" when there is nothing to commit, but without honoring the advise.statusHints
configuration variable, which has been corrected.
See discussion.
See commit 5c4f55f (17 Dec 2019) by Heba Waly (HebaWaly
).
(Merged by Junio C Hamano -- gitster
-- in commit 9403e5d, 22 Jan 2020)
commit
: honoradvice.statusHints
when rejecting an empty commitSigned-off-by: Heba Waly
In ea9882bfc4 (commit: disable status hints when writing to
COMMIT_EDITMSG,
2013-09-12) the intent was to disable status hints when writing toCOMMIT_EDITMSG,
because giving the hints in the "git status" like output in the commit message template are too late to be useful (they say things like "'git add' to stage", but that is only possible after aborting the current "git commit" session).But there is one case that the hints can be useful: When the current attempt to commit is rejected because no change is recorded in the index.
The message is given and "
git commit
" errors out, so the hints can immediately be followed by the user.Teach the codepath to honor the configuration variable.
The hint (now visible in the commit message editor) will be:
no changes added to commit (use "git add" and/or "git commit -a")
Upvotes: 1