threads / discuss / 26604

git commit not committing, confused

Subject: git commit not committing, confused

## tl;dr

One message between Feb 25, 2011 and Feb 25, 2011.

replies: 0people: 1as markdown or json

seanh· Feb 25, 2011, 19:02 UTC · lore
How did this happen?

I have a git repo containing a LOG.txt file. I made some changes to this file and committed them. Actually, I called this script which did so:

	#!/bin/sh -e
	# Append timestamped one-liners to a file and commit the file to git.
	logdir=~/txt
	logfile=LOG.txt
	cd "$logdir"
	if [ $# = 0 ]; then
		# No command-line arguments, just print out the last entry.
		tail -n 1 $logfile
	else
		entry="[`date`] [`hostname`] $*"
		echo $entry >> $logfile
		git commit $logfile -m "$logfile: $*"
		git push
		tail -n 1 $logfile
	fi

The script executes (and shows output from git) with no errors. `git log` shows the commit, `git log -p` shows the changes committed to the LOG.txt file.

However, `git log LOG.txt` does _not_ show the commit. `git status` shows LOG.txt as modified and unstaged. `git diff LOG.txt` shows a diff of the changes to LOG.txt, the same changes so that show up in `git log -P`. After running `git add LOG.txt` again, `git status` still shows LOG.txt as modified and unstaged! `git commit LOG.txt` reports 'no changes added to commit'.

So this doesn't make sense. I don't know what happened or how. git's index seems to have got into a mess. If I clone the repo then cd into the clone and run git status it shows LOG.txt as modified and unstaged, even though this is a brand new fresh clone!

← back to recent threads