git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Amending merge commits?

From
DBDavid Besen <david.besen@hp.com>
Date
Jul 25, 2014, 22:11 UTC
Message-ID
<loom.20140726T001014-124@post.gmane.org>
In-Reply-To
<22F01493C523F940B4B5E53BB6D0F5352275F207@G5W2738.americas.hpqcorp.net>
Besen, David <david.besen <at> hp.com> writes:
Show 5 quoted lines
> 
> 
> Hi folks,
> 
> I think one of my coworkers has stumbled on a git bug -- if you amend a 
merge commit, and then pull, your amends
Show 5 quoted lines
> are lost.
> 
> Is this expected behavior?
> 
> I've reproduced the problem in a script (attached).  I ran it against a 
couple of versions of git (1.7.1,
Show 6 quoted lines
> 1.7.9, 1.8.4, 2.0.0) and in each case it seemed to lose the amend.
> 
> - Dave
> 
> 
> Attachment (amend-merge.sh): application/octet-stream, 1061 bytes
Whoops, accidentally encoded the script, here it is inline:
#!/bin/bash
set -ex

if [ -z "$GIT" ]; then GIT=git; fi GIT_MERGE_AUTOEDIT=no

# Clean up from the last run rm -rf repo.git repo repo2 || :

# Set up a bare "remote" repo $GIT init --bare repo.git

# Check out the "remote" repo $GIT clone repo.git repo

# Add a commit cd repo echo "file" > file.txt $GIT add file.txt $GIT commit -m "Add file.txt" $GIT push origin master

# Make a branch $GIT checkout -b mybranch

# Add a commit on the branch echo "mybranch" >> file.txt $GIT add . $GIT commit -m "Add 'mybranch' line"

# Go back to master $GIT checkout master

# Merge in mybranch to create a merge commit $GIT merge --no-ff mybranch

# Push that back $GIT push

# Amend the merge commit echo "amended" >> file.txt $GIT add . $GIT commit -C HEAD --amend

cd ..

# Make a second checkout $GIT clone repo.git repo2 cd repo2

# Add some unrelated changes to be pulled echo "repo2" > file2.txt $GIT add . $GIT commit -m "Add file2" $GIT push

cd .. cd repo

# Pull $GIT pull --rebase

# Now, we expect the text "amended" to be in file.txt grep amended file.txt

Previous: Besen, DavidNext: Jonathan Nieder
Message 2 of 8 in “Amending merge commits?”
  1. Besen, DavidJul 25, 2014
  2. David BesenJul 25, 2014
  3. Jonathan NiederJul 25, 2014
  4. Besen, DavidJul 25, 2014
  5. Jonathan NiederJul 25, 2014
  6. Sergei OrganovJul 28, 2014
  7. Jonathan NiederJul 28, 2014
  8. Sergei OrganovJul 28, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.