How can I force "git commit -s" using "git commit" command? - git-commit

I'm looking for a way to write the Signed-off-by: tag automatically when I commit.
I tried configuring it through the .git/config file (Reference). I put these lines of code:
[alias]
commit = commit -s
This did not work. As commented below, you can not edit git's own alias (like commit).(Reference)
I also tried using the command (Reference):
git config --global format.signoff true
Also had no effect. This explains why.
I'm looking for any solution that automatically places the tag and allows me to edit the commit message directly on git, without having to use a system alias.

[Edit made after last comment]
I think if I am guessing correctly then, you cannot alias using words which are 'reserved' words for a git command.
However if you do something like this
[alias]
ci = commit -s
Then it will do what you want it to do.

Use the commits hooks to achieve this
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks
prepare-commit-msg
The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created.
It lets you edit the default message before the commit author sees it.
This hook takes a few parameters: the path to the file that holds the commit message so far, the type of commit, and the commit SHA-1 if this is an amended commit.
This hook generally isn’t useful for normal commits; rather, it’s good for commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed commits, and amended commits.
You may use it in conjunction with a commit template to programmatically insert information.

You can use commit.gpgSign option
you can add it per repository by issuing the command below in the repo folder:
$ git config commit.gpgSign true
or for all git repository on your machine:
$ git config --global commit.gpgSign true

Related

Is there a Git config setting to auto-signed-off-by my commits? [duplicate]

I'm looking for a way to write the Signed-off-by: tag automatically when I commit.
I tried configuring it through the .git/config file (Reference). I put these lines of code:
[alias]
commit = commit -s
This did not work. As commented below, you can not edit git's own alias (like commit).(Reference)
I also tried using the command (Reference):
git config --global format.signoff true
Also had no effect. This explains why.
I'm looking for any solution that automatically places the tag and allows me to edit the commit message directly on git, without having to use a system alias.
[Edit made after last comment]
I think if I am guessing correctly then, you cannot alias using words which are 'reserved' words for a git command.
However if you do something like this
[alias]
ci = commit -s
Then it will do what you want it to do.
Use the commits hooks to achieve this
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks
prepare-commit-msg
The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created.
It lets you edit the default message before the commit author sees it.
This hook takes a few parameters: the path to the file that holds the commit message so far, the type of commit, and the commit SHA-1 if this is an amended commit.
This hook generally isn’t useful for normal commits; rather, it’s good for commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed commits, and amended commits.
You may use it in conjunction with a commit template to programmatically insert information.
You can use commit.gpgSign option
you can add it per repository by issuing the command below in the repo folder:
$ git config commit.gpgSign true
or for all git repository on your machine:
$ git config --global commit.gpgSign true

Is it possible to run Gerrit's commit-msg script standalone, not as hook?

I have no Gerrit hook installed
I have simple commit
I would like to check the Change-id of the commit
Is it possible to get the change id by running some command, for example
./commit-msg xyz
?
I don't want to use Eclipse. I don't want to configure hook.
You don't need to manually install the commit-msg hook in every repository you clone. You can configure Git to do this job for you automatically. When you execute the clone command Git copies a repository template located at:
Linux = /usr/share/git-core/templates
Windows = C:/Program Files (x86)/Git/share/git-core/templates
If you add the commit-msg hook to the template it will be installed automatically for every cloned repository.
However, the best thing to do is the following:
Create a personal template (e.g. $HOME/.git-templates)
Install the commit-msg in $HOME/.git-templates/hooks
Configure Git to use your personal template:
git config --global init.templatedir $HOME/.git-templates
The commit-msg script assumes to be run as Git hook (see example file). Therefore, it makes couple of assumptions.
Executing it stand-alone (you just could have tried that, right?) fails with
sed: : No such file or directory
Thus, no, you cannot run this standalone.
You might be able to fix it to work when called manually, but I'm unsure about your motivation. You sound like you don't want to install anything, but git-review is a nice helper.

reversing commits in git

I committed a change locally with Storyboards for iOS. I have not been able to merge them correctly with a friend of mine so I'm giving up. My changes are pretty small and I can redo them later. What I'd like to do is reverse the last commit without the storyboards and just keep my code. I tried following this:
How to undo last commit(s) in Git?
how i interpreted this was:
git reset --soft HEAD^
after this, I did git status, and I saw all my files in green in the staging area, including the storyboards. So i wanted to unstage them (or so I thought). So I did
git reset HEAD MainStoryboard*
Then I did not see my storyboard files on git status. I didn't see them in red either in the unstaged area which I thought was weird. So I then did
git commit -a -c ORIG_HEAD
It allowed me to change my commit message, but the commit was the same. It still commit my storyboard files. So I'm unsure of what is going on here.... Any thoughts? Thanks in advance.
when doing reset, try to use -- to separate file list from revisions
git reset HEAD -- file_list
also use simple commit (not ammend form)
git add your_changed_files
git commit
if unstaging a pattern doesn't work, you can try the approach in "GIT: I want to unstage all files matching a certain pattern":
for i in `git status --porcelain | grep '^M.*MainStoryboard.*$' | sed 's/^M \+//'`; do
git reset HEAD -- "$i"
done

git checkout master command gives error that a file would be overwritten

I just made tried to do git checkout master and I got this error:
macoss-MacBook-Pro-10:Marketing owner12$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
Marketing.xcodeproj/project.xcworkspace/xcuserdata/owner12.xcuserdatad/UserInterfaceState.xcuserstate
Please move or remove them before you can switch branches.
Aborting
but I am not sure how to handle this situation. I don't mind having this file overwritten by what is in the repo. What is the correct way for me to proceed here?
Thanks!
You have files that are not being tracked. Either
rm untracked.file1 untracked.file2
or
git add . && git commit -m "adding new previously untracked files that serve a purpose"
if you're having permission issues:
git add --ignore-errors .
Either delete the file if you don't care about it or stash it if you think you will need it in the future. Or simply rename.
Commit the files you want to keep and then do a git clean to remove the extra files you don't want to keep. This article on the git ready website describes it very well.
If you just want to get rid of one or two files in your working directory then you can do a dry run first and see which files would be cleaned up using:
git clean -n
And then when you are sure do this:
git clean -f
git clean has a -d switch if you want to clean up directories as well. And you can use that together with the other switches, so this is what I would normally use (and then after the dry run change -n to -f):
git clean -n -d
Then after your git clean, use:
git status
to make sure that you have no untracked files or uncommitted changes. And lastly switch to master with:
git checkout master

How to install a plugin from github?

I have tryed to run this code in my console:
script/plugin install git://github.com/apotonick/cells.git
...but i only get an empty folder named "cells" in my "vendor/plugins" dir.
What's wrong?
Check you Git version.
This may be related with you gitconfig file, as described in this thread
The reason is that it appears rails-2.3.5/lib/commands/plugin.rb is trying use git pull to grab the plugin code (see the install_using_git method), which doesn't work right.
Example:
script/plugin install git://github.com/fesplugas/typus.git
mkdir vendor/plugins/typus
cd vendor/plugins/typus
git init
git pull --depth 1 git://github.com/fesplugas/typus.git
That last line exits 1, but that error is being masked by the install_using_git method, and the directory is just rm -rf'ed.
I tracked this down to a conflict with ~/.gitconfig. If I remove these lines it works:
[branch "master"]
remote = origin
merge = refs/heads/master
It appears a naked git pull has problems with these settings.
Actually, the problem would be here because of a global git config file (in your homedir: '~/.gitconfig'), defining a master which may be incompatible with the master expected by the git pull within that specific Git repo.

Resources