在CentOS中进行Flutter代码版本控制,需结合Git工具与Flutter特性,核心步骤如下:
通过Yum安装Git(推荐):
sudo yum update
sudo yum install git
配置全局用户名和邮箱:
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
验证安装:
git --version
flutter create my_flutter_app
cd my_flutter_app
pubspec.yaml(依赖配置)和pubspec.lock(依赖版本锁定)纳入版本控制,执行:git init
git add pubspec.yaml pubspec.lock
git commit -m "Initial commit with dependency configuration"
git add . # 添加所有变更文件
git commit -m "描述变更内容"
git remote add origin https://github.com/your_username/your_repo.git
git push -u origin main
git checkout -b feature/new_feature
合并分支到主分支:
git checkout main
git merge feature/new_feature
若需切换Flutter版本,可使用FVM工具(需先安装):
dart pub global activate fvm
fvm use 3.7.0 # 切换到指定版本
.fvm/flutter_sdk软链接,确保团队使用统一版本。pubspec.yaml中版本号(如^1.2.3)和pubspec.lock锁定具体版本,确保环境一致性。参考来源: