Is it possible to hook a git commit to the save on Textmate?

The one feature that has kept me an Eclipse user is that each time you hit save, a copy of it goes into the Eclipse local history. Then you can do a diff on local history.

Still, I’d like to use Textmate since I heard such great things about it. I know there’s a feature request for a future version…but I’m wondering if someone has found a plugin, or some other way to get this functionality shoehorned into Textmate now? I know it’s a longshot but never hurts to ask.

  • Using custom diff tool with `git show`
  • How to setup Git mirror for big SVN repository?
  • How can I push a part of my git repo to Heroku?
  • How does git-receive-pack work?
  • How do I restore from a previous commit on Xcode 8?
  • How do I tell git to ignore my local changes, but leave the file in my remote repo?
  • Thank you.

    (Edited the title of the question since the previous title got no interest)
    I just realized that perhaps this can be a solution. Is it possible to hook the Textmate save into a git commit?

  • Is there a way to use private git repository with Berkshelf
  • Resolving a part of conflict in a file in GIT
  • my local git repo has “not staged” deleted files, remote is file, how do I pull the missing files?
  • Exceptions in .gitignore
  • Undo a git am --abort
  • what are limitations of shallow clone
  • One Solution collect form web for “Is it possible to hook a git commit to the save on Textmate?”

    What you want is this: Create a new command, set “Save” to “Current File” (this option is above the text area), “Input” to “Entire Document” and “Output” to “Show as Tool Tip”. Now copy the code below into the text area and assign Command-S as the commands key-binding.

    #!/usr/bin/env ruby
    filename = ENV["TM_FILEPATH"].split("/").last
    `git add #{ENV["TM_FILEPATH"]}`
    `git commit -m "#{filename}"`

    Every time you type in Command-S the file will be saved and committed to an (already existing) git repository. If the file wasn’t changed, no commit will be done, because git will block the commit.

    Below I have extended the command to pop up a dialog for the commit message and to give a nice warning, if no git repository was found. You should be able to figure out the rest yourself. 🙂

    #!/usr/bin/env ruby
    require ENV['TM_SUPPORT_PATH'] + '/lib/ui'
    filename = ENV["TM_FILEPATH"].split("/").last
    message = TextMate::UI.request_string(
        :title => "Commiting changes of #{filename}",
        :prompt => "Please enter the commit message for your changes."
    add = `git add #{ENV["TM_FILEPATH"]} 2>&1`
    commit = `git commit -m "#{message}" 2>&1`
    git_answer = add + commit
    unless git_answer.grep(/fatal/).empty?
      puts "Please initialize git repository first!"
    Git Baby is a git and github fan, let's start git clone.