Contents

Git Contribution

Contribution graph shows activity from public repositories. You can choose to show activity from both public and private repositories, with specific details of your activity in private repositories anonymized.

Update local git config

1
2
3
git config --global user.name “github’s Name”
 
git config --global user.email "github@*.com"

Update commit history

If you do not want to waste your commit history.

we can use ‘git log’ to see the git record

1
git log

we need to edit all of the history of commit and push.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
git filter-branch -f --env-filter '
if [ "$GIT_AUTHOR_NAME" = "oldName" ]
then
export GIT_AUTHOR_NAME="newName"
export GIT_AUTHOR_EMAIL="newEmail"
fi
' HEAD
 
git filter-branch -f --env-filter '
if [ "$GIT_COMMITTER_NAME" = "oldName" ]
then
export GIT_COMMITTER_NAME="newName"
export GIT_COMMITTER_EMAIL="newEmail"
fi
' HEAD

如果无差别把所有都改的话去掉if..fi

1
2
3
4
5
6
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='newName';
GIT_AUTHOR_EMAIL='newEmail';
GIT_COMMITTER_NAME='newName';
GIT_COMMITTER_EMAIL='newEmail'
" HEAD

Update Git push

你这里将你本地git的账户和邮箱重新设置了,但是github并没有那么智能就能判断你是原来你系统默认的用户.

也就是说你新配置的用户和你默认的被github识别成两个用户.

这样你以后操作的时候commit 或者 push的时候有可能产生冲突.

Solution:

  1. 使用强制push的方法:
1
git push -u origin master -f

这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。

  1. push前先将远程repository修改pull下来
1
2
git pull origin master
git push -u origin master
  1. 若不想merge远程和本地修改,可以先创建新的分支:
1
2
3
git branch [name]
#然后push
git push -u origin [name]