Is there a Git config setting to auto-signed-off-by my commits? [duplicate] - 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

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

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

Force git to ignore a directory and all present and future files within

So, I'm a newbie at git, but I'm using it because I have my rails app deployed through heroku. My app generates a bookmarklet (which is just a js file) for each user upon sign-up. Unfortunately, when I deploy, all of the bookmarklets for the users on the live site get overwritten with the bookmarklets for the users on my dev environment. I've read some other questions about this kind of thing, and I know I'll have to add the bookmarklet folder to the .gitignore file, and something about rm --cache (but I'm not sure exactly what I'll have to do). I tried doing these things, but I'm wondering if the problem is that git is ignoring all of the files that are there now, but isn't ignoring the ones that are generated after doing the whole gitignore process. Either that or I'm just doing it wrong (this is very, very likely).
Any help is welcome. And sorry that this covers the same ground as a lot of other similar questions. I did as much research as I could.
Thanks.
Here some simple steps:
Create a file .gitignore in the root of your repository, with the following simple content:
/path/to_your/folder
Add the file to your repository:
git add .gitignore
Remove the folder from your repository (this won’t physically delete the folder):
git rm --cached /path/to_your/folder
Commit
git commit
After that, the folder should be removed from your repository and subsequent changes in it will be ignored by git.
Sounds like Heroku is cleaning out every file not checked in to your Git repository when you deploy. Modify your app to save the bookmarklets to a directory outside of your Git repository.
#poke's answer is mostly correct, but the leading slash in the path name is problematic so I'm posting revised instructions.
The following steps assume the subdirectory inside your git repository is named foo.
Make sure you're at the top level of your Git working directory:
cd "$(git rev-parse --show-toplevel)"
Add foo to your top-level .gitignore file:
echo /foo/ >>.gitignore
The leading slash says to ignore foo in the top level but not */foo or */*/foo, etc. The trailing slash says to ignore foo if it is a directory, but not if it is a file or symbolic link.
Stage the newly modified .gitignore:
git add .gitignore
Commit:
git commit -m "Add foo to .gitignore"
Stop tracking the contents of the foo directory in the Git repository:
git rm -r --cached foo
The --cached option tells Git to not delete the foo folder from your working directory.
Commit:
git commit -m "Remove the foo directory"
Add the following to your .gitignore:
path/to/ignore/**/*
If there are already tracked files on that path, they won't be ignored.
You'll have to run
git rm -r --cached path/to/ignore/

Resources