0

So here's what happened:

  • I have a local repo for dev
  • pushed to origin master
  • from my test env I always do git pull to update

Now of course I have different config files in the test env. I locally changed my config file on test env. In a hurried moment (...) I committed my local changes after a merge was conflicting. Now the app runs fine, but git tells me

Your branch is ahead of 'origin/master' by 13 commits.

I understand, as I committed my local change - which I do NOT wish to push to master. What would be the correct way to fix this? I want to:

  • Have my local copy of the config file
  • do not want to mess up with the basically correct config on the test env
  • get rid of the 'your branch is ahead' message
  • keep my master and my test env clean

Thanks!

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
transient_loop
  • 5,984
  • 15
  • 58
  • 117
  • What about those 13 commits in between? You're ok with trashing them? – Nic Oct 31 '12 at 18:44
  • 2
    As a "best practice" the configuration files should never be in source control. The problem is that now you may have sensitive credentials in source control. Instead, store a template/example that you keep up to date and use a `.gitignore` rule on the configuration file. – Robert K Oct 31 '12 at 18:47
  • @Nic looks like these are most "Merge branch 'master'" commits from my pushes from dev... – transient_loop Oct 31 '12 at 18:59
  • configuration files are unavoidable in source control, especially in some frameworks based in Java, for example. You need the configuration files to not work out of the box from source and rely on scripting or scripting through smudge/clean scripts via git attributes to handle them properly. – Adam Dymitruk Nov 01 '12 at 16:27

2 Answers2

1

You want to throw away your local commits on dev with

git push -f . origin/master:master

or

git reset --hard origin/master

if you are on that branch already.

The best way to treat config transformations is with smudge/clean scripts. They are explained it the progit.org/book in the attributes chapter. You commit a config that will work nowhere. Rely on the scripts to transform the config to what it needs to be on each environment.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • ok, so I'd need to first check what were those 13 commits... how can I get a list of those 13 commits only? Would that be `git log origin/master..HEAD` (from http://stackoverflow.com/questions/2016901/viewing-unpushed-git-commits) – transient_loop Oct 31 '12 at 18:55
0

If you just want to change your most recent commit, it is pretty easy. You stage the changes you want to make, and then amend your last commit.

In your case, you would change your config file back to the way you want it, stage it, then commit an amendment. Using config.php for your config file, it would look like:

$ git add config.php
$ git commit --amend

See the Rewriting History chapter of Pro Git

slashingweapon
  • 11,007
  • 4
  • 31
  • 50