Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github: How would you delete all commits by a certain username

Tags:

git

github

When I first started out with this repo, I hadn't used git before and biffed the setup by mistyping my email or something so all commits for a while were made by the user "unknown." I found an answer on here to convert all the "unknown" commits to my name but what it actually did was duplicate the commit and apply my name. So now I have all these "unknown" user commits scattered.

So I was wondering about some commands to run to delete all commits by "unknown" user.

like image 888
Justen Avatar asked Nov 08 '11 23:11

Justen


People also ask

How do I delete multiple commits in github?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

Can you delete commit history in github?

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history.


1 Answers

You will have to make use of git filter-branch (in your repo ) and force push to github.

Example from manual that deals almost the same situation where you want to remove commits from a particular user:

git filter-branch --commit-filter '
    if [ "$GIT_AUTHOR_NAME" = "Darl McBribe" ];
    then
            skip_commit "$@";
    else
            git commit-tree "$@";
    fi' HEAD

Note that this will rewrite your history and it might affect others who also use your repo.Github advice on collaborators:

Dealing with collaborators

You may have collaborators that pulled your tainted branch and created their own branches off of it. After they fetch your new branch, they will need to use git rebase on their own branches to rebase them on top of the new one. The collab should also ensure that their branch doesn’t reintroduce the file, as this will override the .gitignore file. Make sure your collab uses rebase and not merge, otherwise he will just reintroduce the file and the entire tainted history… and likely encounter some merge conflicts.

http://help.github.com/remove-sensitive-data/

like image 125
manojlds Avatar answered Nov 15 '22 15:11

manojlds