git update-index --assume-unchanged path/to/file
git update-index --no-assume-unchanged path/to/file
git ls-files -v | grep '^[[:lower:]]'
git diff-tree --no-commit-id --name-only -r 'hash of the commit'
--no-commit-id suppresses the commit ID output.
--pretty argument specifies an empty format string to avoid the cruft at the beginning.
--name-only argument shows only the file names that were affected (Thanks Hank).
Use --name-status instead, if you want to see what happened to each file (Deleted, Modified, Added)
-r argument is to recurse into sub-trees
git add the_left_out_file
git commit --amend --no-edit
git fetch origin main
git merge origin/main
NOTE: This answer changes SHA1s, so take care when using it on a branch that has already been pushed. If you only want to fix the spelling of a name or update an old email, git lets you do this without rewriting history using .mailmap. See my other answer.
Using Interactive Rebase
git rebase -i -p <some HEAD before all of your bad commits>
Then mark all of your bad commits as "edit" in the rebase file. If you also want to change your first commit, you have to manually add it as the first line in the rebase file (follow the format of the other lines). Then, when git asks you to amend each commit, do
git commit --amend --author "New Author Name <[email protected]>"
edit or just close the editor that opens, and then do
git rebase --continue
to continue the rebase.
You could skip opening the editor altogether here by appending --no-edit
so that the command will be:
git commit --amend --author "New Author Name <[email protected]>" --no-edit && \
git rebase --continue
As some of the commenters have noted, if you just want to change the most recent commit, the rebase command is not necessary. Just do
git commit --amend --author "New Author Name <[email protected]>"
This will change the author to the name specified, but the committer will be set to your configured user in git config user.name
and git config user.email
. If you want to set the committer to something you specify, this will set both the author and the committer:
git -c user.name="New Author Name" -c [email protected] commit --amend --reset-author
git reset
How it works: • It changes the current branch (HEAD) to point to a different commit. • It can modify the staging area and working directory depending on the options used.
Let's check what option git reset
offers us:
--soft
: Moves HEAD to the specified commit but leaves the staging area and working directory unchanged.
--mixed
(default): Moves HEAD and resets the staging area to match the specified commit; the working directory remains unchanged.
--hard
(yolo): Moves HEAD, resets the staging area, and resets the working directory to match the specified commit. All changes after that commit are lost.