29

I was exploring the git config options using tab completion in bash, and without really thinking, I did this:

git config --global user.signingkey --help

and now my global signing key is set to --help. Facepalm. Is there a generic way to find out what these config settings where in the past, or is there somewhere that I could look in a project to see what this might have been set to? I have a Github account, maybe I could get the old value from there, since I haven't pushed anything since the mistake? I'm not even sure if it was set to anything, but I do use SSH with Github.

cd <another project's location>; git config user.signingkey

returns --help.

AhmadAssaf
  • 3,556
  • 5
  • 31
  • 42
Dan Ross
  • 3,596
  • 4
  • 31
  • 60
  • 1
    `git config --global` will write changes to your `.gitconfig` file in your home directory - try `cat ~/.gitconfig` to view contents, maybe just comment out the line with user.signingkey that you added? – house9 May 27 '13 at 22:23
  • @house9 After commenting it out, `git config user.signingkey` returns nothing. That may have been it's original setting, I just don't know. For now, I will leave it commented out, and if I run into problems, I will set it appropriately. I feel like such a noob right now. Thanks for the suggestion. – Dan Ross May 27 '13 at 22:27
  • `.gitconfig` is in my dotfiles repo, yay! It was unset originally. For me, the problem is solved, but I will leave the question open for the sake of those who don't have a dotfiles repo. – Dan Ross May 27 '13 at 22:31
  • 2
    Ah, another person with a dot-files repo! I made a directory, ~/Dotfiles, and put most of my config and .foorc files in there so that ~/.foorc is a symlink to ~/Dotfiles/foo. – torek May 27 '13 at 22:37
  • @torek, That's exactly how I do it too, and I am considering writing a moving-helper script / makefile to make those links for me when I set myself up on a new machine. – Dan Ross May 27 '13 at 22:42
  • @DanRoss, for your comment above, I think you'll find this article helpful; I just came across it recently and haven't had a chance to try it yet but: [Using GNU Stow to Manage Your Dotfiles](http://brandon.invergo.net/news/2012-05-26-using-gnu-stow-to-manage-your-dotfiles.html) – Wildcard Jul 02 '19 at 21:37

1 Answers1

55

Command

git config --global section.key value

does nothing more than editing file ~/.gitconfig with content like this:

[section]
key = value

So, you can simply edit this file and fix it.

Also, you can use command to remove offending setting:

git config --global --unset section.key
mvp
  • 111,019
  • 13
  • 122
  • 148
  • I actually just `git reset --hard` my dotfiles repo, but what I was asking was how to reset the config setting to it's previous value, if that is even possible? When I asked, I hadn't thought about the dotfiles repo, and I left the question open for those who don't have one. I would have had no way of knowing that the parameter had never been set, without the good old dotfiles. – Dan Ross May 27 '13 at 23:13
  • 1
    If you were tracking your `~/.gitconfig` in your dotfiles repo, then you should be able to use `git log` in dotfiles repo to find this out - provided you were committing all changes to your dotfiles, including `.gitconfig`. – mvp May 27 '13 at 23:16
  • I did a `git diff` before `git reset`. – Dan Ross May 27 '13 at 23:20
  • But what if I hadn't committed to the dotfiles repo since before user.signingkey was set to a correct value? – Dan Ross May 27 '13 at 23:21
  • If I'm getting too hypothetical for this question to be useful, feel free to close / lock / remove it. – Dan Ross May 27 '13 at 23:23
  • If you were changing files without committing, then you will not be able to tell what state they were between commits (unless you have funky filesystem with snapshot capabilities). Regarding closing/locking/removing questions: most users cannot do it alone. It takes 5 3k-rep users to close, and 3 20k-rep users or moderator to delete a question. – mvp May 27 '13 at 23:28
  • Ok, so basically it's up to the user to keep their config files under version control or keep backups, or else they are screwed when they screw up. That's fair, everyone is supposed to make backups. With the dotfiles option mentioned in these comments, I think this answer sums up the best possible solution. – Dan Ross May 27 '13 at 23:34
  • 3
    It's probably a sign of some character defect of mine that I actually *prefer* to just edit ~/.gitconfig (and other git config files) with vi/vim, rather than using "git config". :-) (I know, there's also `git config -e`...) – torek May 27 '13 at 23:38