1

I know this may sound crazy but I think it will work.. We have to report quick wins each week to the manger so what I was thinking is that we can use git to do the logging and then the manager can just pull the pass 7 days of the log.

so I create a git repo with the following command

mkdir mynotes.git
cd mynotes.git
git init

I then create this script in it:

#!/bin/sh
clear
echo "Quick Logging (Press Enter on a blank line to exit)"
while true
do
    echo
    read -p "log> " logtext
    if test -z "$logtext"
    then
        exit 0
    else
    git commit --allow-empty -m "$logtext"
    fi
done

So then each much of the team can do a git pull and push to the repo.. The issue that I am having is that if someone pushed to the repo as someone else is logging and then trys to push we get this error.

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@git.xxxx.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

How can we make this system work.. it sounds like something great if we can get it working

JohnNY
  • 539
  • 1
  • 3
  • 9

1 Answers1

3

Although the reason you are getting an error is a duplicate of this question, let me give you more details because it seems you are mixing up workflow with reporting...

So then each much of the team can do a git pull and push to the repo

Assuming that you are doing the above step like you described, your pull most likely failed due to a conflict. You must resolve your conflict to finish the merge before pushing your changes. Do a git status to see conflicted files, modify them, git add them to stage them, then commit and push.

I would recommend another approach. Manage the merges in your development workflow, and do your 7-day reporting seperately. The git log command has a nice option for that:

git log --since="7 days ago"

Check the manual of the git log command because it has tons of other useful formatting options.

git log --since="7 days ago" --pretty=format:"%ad|%h|%cn|%s"

You could use that git log command on a dedicated local repository which only pulls from your remote right before you want to print the 7-day log, or redirect it to a file or another script.

Community
  • 1
  • 1
Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29
  • this is not really a duplicate of the above question. my project has not files and no one is going to be putting in files we are using commits for logging as a logging system. The issue is that someone may forget to do a pull before a push or someone can do a pull and push before someone does a push... its only commit logs.. no files – JohnNY Feb 27 '13 at 14:22
  • ok, that is more clear, thanks. You could integrate `git pull` and `git push` inside your script, before and after the commit command, to limit the chances of this occurring. – Sébastien Dawans Feb 27 '13 at 14:29
  • yes I was thinking that but I dont want the output of the git pull and push to goto the screen? Plus I still have the odds of someone doing a pull and someone else doing a pull and push before he enters the commit and pushes it back. – JohnNY Feb 27 '13 at 14:35
  • Create branches for each of the participants? The manager can take them all and merge if required. BTW, you are just saving the commit messages; perhaps some hack around `syslog(3)` would be better suited for short, time and origin stamped messages. – vonbrand Feb 27 '13 at 18:56