notes icon indicating copy to clipboard operation
notes copied to clipboard

git攻略

Open v5tech opened this issue 10 years ago • 0 comments

http://jlord.us/git-it/index.html

1.修改第一次提交

git rebase -i --root
git commit --amend
git rebase --continue

1)git rebase -i默认会打开nano编辑器,将要修改的commit id标记为edit,然后按下键盘CTRL+O保存、CTRL+X退出。

2)git commit --amend 修改提交

参考链接

2.修改最近一次提交

git commit -a --amend -m "commit msg"

3.修改第N次提交

git rebase -i HEAD~N
git commit --amend
git rebase --continue

4.从所有提交中删除一个文件

git filter-branch --tree-filter 'rm -f passwords.txt' HEAD

5.全局性地更换电子邮件地址

git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "root@ruby" ];
then
        GIT_AUTHOR_NAME="sxyx2008";
        GIT_AUTHOR_EMAIL="[email protected]";
        git commit-tree "$@";
else
        git commit-tree "$@";
fi' HEAD

或者

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='冯靖'; GIT_AUTHOR_EMAIL='[email protected]'; GIT_COMMITTER_NAME='ameizi'; GIT_COMMITTER_EMAIL='[email protected]';"

git push -u -f

v5tech avatar Jan 16 '15 07:01 v5tech