Git 配置与技巧
1. Configuration
Section titled “1. Configuration”SSH Key Generation
Section titled “SSH Key Generation”Generate a new SSH key (RSA 4096-bit):
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"User Identity
Section titled “User Identity”Set your global username and email:
git config --global user.name "Your Name"git config --global user.email "your_email@example.com"Proxy Settings
Section titled “Proxy Settings”Configure Git to use a proxy (e.g., HTTP proxy at 127.0.0.1:8888):
git config --global http.proxy http://127.0.0.1:8888git config --global https.proxy http://127.0.0.1:8888To unset:
git config --global --unset http.proxygit config --global --unset https.proxy2. Modify Commit History
Section titled “2. Modify Commit History”Rewriting history is destructive. Ensure you have a backup before proceeding. git filter-branch is deprecated; consider using git-filter-repo for better performance and safety.
Change Author Info (All Commits)
Section titled “Change Author Info (All Commits)”git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL=new_email@example.com' --Change Specific Author Info
Section titled “Change Specific Author Info”Replace Old@Email, Changed Name, and Changed@Email with actual values.
git filter-branch -f --env-filter 'OLD_EMAIL="Old@Email"CORRECT_NAME="Changed Name"CORRECT_EMAIL="Changed@Email"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"fiif [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"fi' --tag-name-filter cat -- --branches --tags3. Logs
Section titled “3. Logs”Filter by Author
Section titled “Filter by Author”git log --author="Author Name"4. Tips
Section titled “4. Tips”- Git History Visualization: Replace
.comwith.githistory.xyzin any GitHub file URL to see a visual history of that file.