Reputation: 17900
I get a very strange behaviour. I have a bash script that runs on Bamboo, which sets the desired git user, commits some changes, then pushes them to the master branch.
The problem is that, the commit is done with the correct user, but the push is done with a different user.
The commit looks something like:
USERX authored commit 7d365...
And then the push:
USERY pushed to master at user/repo
The commit and push are done one after another after setting the username and email, so why is this happening, what should I look for? Here's part of my bash script:
git config user.name "$bamboo_GIT_USER_NAME"
git config user.email "$bamboo_GIT_USER_EMAIL"
git add -v CHANGELOG.rst || exit 3
git commit -v -m "Updated CHANGELOG.rst" || exit 3
git push origin "$bamboo_GIT_BRANCH" -v || exit 3
Upvotes: 5
Views: 3597
Reputation: 487755
Commits are actual things (specifically, "objects") that live inside the git repository. They contain text strings giving the author and committer. Once written into an object, these are permanent and unchangeable.
Aside: git commit --amend
does not change them; instead, it makes a new, different commit, with different data in the commit, and points the branch-head to the new commit:
... - E - F - G <-- master
If you then git commit --amend --author='someone else <[email protected]>'
, git abandons the old tip commit (G
), adding a new commit (G'
):
... - E - F - G [abandoned]
\
G' <-- master
When you do a git push
, this does something very different.
Let's say, for instance, you first git fetch
some commits written by someone else, from a repository at git://else.where/path/to/repo.git
. Or, you write your own commits with user.name
and user.email
set to some unusual values.
git add
but no git commit
.Then you git push
these commits (written by someone else, or committed with odd user.name
and user.email
) to ssh://[email protected]/different/path/to/repo.git
.
Here, you package up the commits you retrieved, and deliver them to your other server. But it's you (specifically, mylogin
) logging in via ssh to some.place
, delivering the commits; the commits you deliver are the permanent, unchangeable repository objects you retrieved from else.where
, or made under the settings you put in user.name
and user.email
.
Note that git does not authenticate you or log you in to the host some.place
. It's ssh that authenticates you and logs you in, as you (or rather, [email protected]
). Your ssh session then runs the git command that receives the git objects you send. If you ask, on some.place
, what user is running ssh, you get mylogin
: that's who logged in via ssh. This is completely disconnected from the author and committer names stored in the commits being uploaded.
Upvotes: 6
Reputation: 425
It's supposed to be like that.
To change the author of the last commit:
$ git commit --amend --author='somebody <[email protected]>'
Upvotes: 0