Questions tagged [git-amend]

Parameter of git-commit command that adds the current staging area to the last commit and allows you to (by default) edit previously used commit message or (if other options were given) reuse it or even discard it and write a new one.

New commit!

Using this option effectively creates new commit! It replaces current tip of the branch, so if you use it on anything that's NOT the tip (checking out a tag or SHA and then amending) you're effectively branching (feel free to check with logs).

It's considered a rough equivalent of

  • soft reset,
  • manual changes
  • and committing on top of ORIG_HEAD.

Trivia

  1. You may also use it to amend a merge commit.
  2. Using --reset-author with --amend you also reset author and author timestamp.

More:

git help commit

146 questions
3
votes
2 answers

Git not-fast-forward errors after git commit --amend

I used git commit --amend to amend the previous commit. After that when I push my changes, I was rejected because of 'not -fast-forward' Errors. I have search for answers. Unfortunately, commands such as, git pull --rebase, git fetech origin don't…
user1332907330
  • 113
  • 2
  • 7
2
votes
1 answer

In pre-commit hook, find hash of the parent of the commit that's being created

I have some tests in my pre-commit hook which require the hash of the previous commit to work. By previous commit I mean the one that will become the parent of the commit that's being created right now. Normally, I can just use git rev-parse…
Piotr Siupa
  • 3,929
  • 2
  • 29
  • 65
2
votes
1 answer

Quick, small, casual git rebase for only one or a few hunks: any facility?

I'm in the process of editing my source files to produce a new commit atop my dev branch. My changes are saved on disk but not yet staged. Then I notice a small mistake introduced by a former commit, say HEAD~10. Once fixed, the result is only one…
iago-lito
  • 3,098
  • 3
  • 29
  • 54
2
votes
2 answers

Git commit --amend alias hangs

I have this alias in my ~/.gitconfig: [alias] am = commit -a --amend -C HEAD Yet, when I run git am, it hangs, and I get (master|AM/REBASE) at the prompt, and I have to run git am --abort.
Geremia
  • 4,745
  • 37
  • 43
2
votes
1 answer

Git alias with multiple command

After a review, i need to change some code and repush all my change code on the remote branch. So i would like to automate on git with an alias (ex: git repushall) these different commands: git add . git commit --amend (and ctrl + x) git push…
Tim
  • 162
  • 2
  • 10
2
votes
3 answers

How to undo multiple “git commit --amend" or to get difference for each amend commit?

I did by mistake more than 100 amend commits. How can i convert them to usual commits? Or at least to get git log with difference for each amend commit? I can see only difference for all amend commits at once if i run gitk or git log -p now. i can…
l0pan
  • 476
  • 7
  • 11
2
votes
1 answer

Can I amend a commit to the master branch from a new local branch?

I recently committed a file to the master branch of my work's repository. I then created a new local branch to work on other things, but realised I had missed something on the original commit. I made the changes while in the new branch. Would git…
Oscar Chambers
  • 899
  • 9
  • 25
2
votes
1 answer

How to make Git warn me about changing pushed commits?

tl;dr: Committing something, pushing that, amending that commit and trying to push again without using --force fails. How to set up Git so that it tells, when I try changing 'published commits'? I am using Git for quite some time now and it still…
Kreuvf
  • 273
  • 3
  • 6
2
votes
2 answers

Git - do amended commits persist?

On my Git branch, I created a commit and pushed. later, I added changes to the index, used git commit --amend, and then git push -f. My new commit overrode the first one both locally and remotely on my branch. At this point, I'd expect (or want) the…
user976850
  • 1,086
  • 3
  • 13
  • 25
2
votes
0 answers

Change previous commit message after merging with another branch

I have a situation where I need the change the commit message of a previous commit on a branch (lets call it BranchA). I understand that I can change the message using an interactive rebase on that branch git rebase -i . The problem…
Benjen
  • 2,835
  • 5
  • 28
  • 42
2
votes
2 answers

git mirroring to GitHub and filtering private files

Currently working on a project. We want to open-source our day-to-day commits with full info (author, etc...) while filtering out some specific private folders. Let's say I commit A/file1 and B/file2 in branch master, I would like to have it…
xen2
  • 111
  • 5
2
votes
1 answer

Git: Allow amending commits without erasing the history

Is there an option in Git to allow amending commits in a central repository (e.g. to change the description, committer name or his/her e-mail address), but not allowing to erase the entire history. As I understand it, by default both are allowed…
Det
  • 3,640
  • 5
  • 20
  • 27
2
votes
2 answers

Is there a light-touch way to alter a single file that was accidentally committed?

I made a commit containing ten files recently. One of the files shouldn't have been committed: it has my local test changes that won't work for anyone else. I'd like to check out that file from a previous commit, then re-commit it as the original,…
jkj2000
  • 1,563
  • 4
  • 19
  • 26
2
votes
1 answer

How to remove a file from a git commit to push to svn

I replaced a folder and all its contents with a symlink. That is removed the folder and added a symlink, in a single git commit. Git commit happened normally. However when I try to push to the upstream svn, it complains that the file exists. Now,…
lprsd
  • 84,407
  • 47
  • 135
  • 168
2
votes
2 answers

Does Git store amends?

I know they exist in git reflog, but if I push a commit to a remote repository, amend, then git push --force (warning: pushing --force to remote repositories should usually be avoided), will the commit that I overwrote exist somewhere?
mustafa.0x
  • 1,476
  • 2
  • 17
  • 30