How to run git commit -m '...'
command from another directory?
I edit my file:
vim /home/.../myFile
I add it using:
git add /home/.../myFile
But now, how can I commit the changes?
git commit -m '...' ???
How to run git commit -m '...'
command from another directory?
I edit my file:
vim /home/.../myFile
I add it using:
git add /home/.../myFile
But now, how can I commit the changes?
git commit -m '...' ???
You can use git -C <path> <command>
.
From https://git-scm.com/docs/git/2.4.4
git -C <path> commit -m "Some commit message"
Runs as if git was started in <path> instead of the current working directory.
You can also use the environment variables $GIT_DIR
and $GIT_WORK_TREE
to the same effect as --git-dir
and --work-tree
These are the steps to commit a file when you are in another directory:
git --git-dir=/path/to/my/directory/.git/ --work-tree=/path/to/my/directory/ add myFile
git --git-dir=/path/to/my/directory/.git/ --work-tree=/path/to/my/directory/ commit -m 'something'
After commiting everything with the --git-dir
parameter there where several files deleted from the repo and I had to recover them.
For me the best solution was in a script to do a cd
to the other folder and then execute the git commands. Was way less code to write without the parameters in every command.