Reputation: 2827
I have outsourced some tasks to other users. Made a copy of the main repository (work) to a different remote (private). The coworker committed changes to the private remote and I would like to push these commits to the work remote with my user. Is there built-in way for this in git or some workarounds?
Upvotes: 2
Views: 47
Reputation: 11558
You can do interactive rebase with edit :)
Before you push (probably you want to hide this information ;)) please verify author & commiter in git to not get into trouble ;)
Please also consider remember that you can force push if you did mistake.
Example on 2 commits:
* cd6b0ac (HEAD -> master) Fix test file
* e3e822e Add test file
Long version (git log
)
commit cd6b0ac5a33283743f524463d0e78a2d3e335e4d (HEAD -> master)
Author: Bob <[email protected]>
Date: Thu Nov 29 10:26:12 2018 +0000
Fix test file
commit e3e822e89397fdadbd1c6e1ac6710d96590d92c6
Author: Bob <[email protected]>
Date: Thu Nov 29 10:25:53 2018 +0000
Add test file
Now I will rebase with edit.
git rebase -i e3e822e89397fdadbd1c6e1ac6710d96590d92c6
In console now I will see:
pick cd6b0ac Fix test file
# Rebase e3e822e..cd6b0ac onto e3e822e (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
... (more I don't want paste)
So for this commit I pick e
and save->quit.
e cd6b0ac Fix test file
So now your working tree will be checkout to that commit. Now you need to do 2 steps:
git commit --amend --author="Dawid <[email protected]>"
git rebase --continue
go to next commit you picked to edit or finish rebase.Now git log
to verify
commit ec0949d075626ed9416d74c02bcbed721b8be2fe (HEAD)
Author: Dawid <[email protected]>
Date: Thu Nov 29 10:26:12 2018 +0000
Fix test file
commit e3e822e89397fdadbd1c6e1ac6710d96590d92c6
Author: Bob <[email protected]>
Date: Thu Nov 29 10:25:53 2018 +0000
Add test file
If you want to pick more commits to rebase you can write such thing: git rebase -i HEAD^^
(pick last 2 commits)
To verify use git log --pretty=full
commit ec0949d075626ed9416d74c02bcbed721b8be2fe (HEAD)
Author: Dawid <[email protected]>
Commit: Dawid <[email protected]>
Fix test file
commit e3e822e89397fdadbd1c6e1ac6710d96590d92c6
Author: Bob <[email protected]>
Commit: Bob <[email protected]>
Add test file
Read about git rebase
Upvotes: 1
Reputation: 2962
Clone your coworker repo locally and execute like in the following command:
git filter-branch --env-filter 'export GIT_AUTHOR_NAME="Super Man"; export GIT_AUTHOR_EMAIL="[email protected]"'
(put the desirable user name and mail in place of the fictional character ones)
Warning: this will rebase the tree and all commit ids will change
Now you can push it.
See also Changing author info on GitHub
Upvotes: 1