1.5 版本控制(GitHub)
一、基本配置
git config --globaluser.name "你自己的用户名"
git config --globaluser.email "你自己的邮箱"ssh-keygen -t rsa -C"你自己的邮箱" git config --global init.defaultBranch maingit init二、提交与拉取
三、高级操作
四、脚本制作
最后更新于
git config --globaluser.name "你自己的用户名"
git config --globaluser.email "你自己的邮箱"ssh-keygen -t rsa -C"你自己的邮箱" git config --global init.defaultBranch maingit init最后更新于
git add .git commit -m "first commit"git remote add origin git@github.com:peiyafei/HrClient.gitgit branch -m master maingit add .
git commit -m "add new changes"git push origin maingit push origin main --forcegit reset --hard HEADgit pull origin <branch-name>#!/bin/bash
# 确保 build 文件夹被忽略
if ! grep -q "^build$" .gitignore; then
echo "build" >> .gitignore
echo "Added 'build' to .gitignore"
fi
# 使用固定的提交信息
commit_message="修复了一些已知问题"
移除 Git 缓存中的所有文
git rm -r --cached .
# 添加所有更改到暂存区(忽略被 .gitignore 忽略的文件)
git add .
# 提交更改
git commit -m "$commit_message"
# 推送更改到远程仓库
git push origin main
# 显示当前分支状态
git status
#!/bin/bash
# =============================================================
# 文件名:git_auto_commit.sh
# 说明:自动提交脚本
# 作者:peiyafei
# 创建日期:2025-01-03 00:27:27
# =============================================================
# 设置 Git 换行符配置
git config core.autocrlf true
# 创建 .gitattributes(如果不存在)
if [ ! -f .gitattributes ]; then
cat > .gitattributes << EOF
* text=auto
*.sh text eol=lf
*.gitignore text eol=lf
*.cpp text eol=lf
*.h text eol=lf
*.qml text eol=lf
*.txt text eol=lf
*.md text eol=lf
EOF
echo "Created .gitattributes file"
fi
# 检查并创建 .gitignore
if [ ! -f .gitignore ]; then
cat > .gitignore << EOF
# Build directories
build/
debug/
release/
# IDE files
.vscode/
.idea/
*.user
*.pro.user
CMakeLists.txt.user
# Generated files
*.o
*.obj
moc_*
qrc_*
ui_*
# Temporary files
*~
*.autosave
EOF
echo "Created .gitignore file"
elif ! grep -q "^build/$" .gitignore; then
echo "build/" >> .gitignore
echo "Added 'build/' to .gitignore"
fi
# 添加所有更改到暂存区
git add .
# 提交更改
git commit -m "修复了一些已知问题"
# 推送到远程仓库
git push origin main
# 显示状态
git status
echo "============================================================="
echo "Commit completed at: $(date '+%Y-%m-%d %H:%M:%S')"
echo "By user: $(git config user.name)"
echo "============================================================="chmod +x git_auto_commit.sh./git_auto_commit.sh