[Git]Managing Project Versions with Git | 使用 Git 管理開發專案中的版本
SDE Simple Tips Notes | SDE 簡單技巧筆記
Git Commands| Version Control
In software development, continuously updating your project with new features is common. However, overwriting old features with new ones isn’t efficient for long-term projects. This is where version control comes in. For instance, version 1.0.0 contains the initial features, and version 1.0.1 includes advanced features. When you release version 1.0.1 in a new branch, the code from version 1.0.0 remains preserved in the old branch. You can track the corresponding code of versions like v1.0.0 and v1.0.1 using tags in GitHub.
在軟體開發中,不斷更新項目的新功能,是很常見的。然而,直接用新功能覆蓋舊功能,對於長期專案開發來說,效率不高。這就是用Git,控制版本的用武之地。當您在新分支中發布版本 1.0.1 時,版本 1.0.0 中的程式碼,仍保留在舊分支中。您可以透過GitHub中的標籤,追蹤v1.0.0、v1.0.1等版本對應的程式碼。
This is my last blog about using git commands to remotely push updates from VS Code to a Github repository. If you are interested, please take a look.
這是我上一篇關於,使用 git 命令從 VS Code 遠端推送更新,到 Github 儲存庫的博客 。如果有興趣,歡迎看一下。
Blog Navigator — Git Commands for
Git Commands for Releasing a New Version
Below are the steps and commands to release a new version using Git:
1. Ensure all changes are committed on the `develop` branch:
# Switch to the develop branch
git checkout develop
# Stage all changes
git add .
# Commit the changes with a message
git commit -m "Commit latest updates"
# Push the changes to the remote repository
git push origin develop
2. Create a release branch for the new version:
# Create and switch to a new branch for the release
git checkout -b release/v1.0.1
# Stage all changes
git add .
# Commit the changes with a message
git commit -m "Prepare release v1.0.1"
# Push the release branch to the remote repository
git push origin release/v1.0.1
3. Merge the release branch into the `main` branch and push the changes:
# Switch to the main branch
git checkout main
# Pull the latest changes from the remote main branch
git pull origin main
# Merge the release branch into the main branch
git merge release/v1.0.1
# Push the merged changes to the remote main branch
git push origin main
4. Tag the new release and push the tag:
# Create an annotated tag for the new release
git tag -a v1.0.1 -m "Release version 1.0.1"
# Push the tag to the remote repository
git push origin v1.0.1
Example Commands in Sequence:
# Switch to the develop branch
git checkout develop
# Stage all changes
git add .
# Commit the changes with a message
git commit -m "Commit latest updates"
# Push the changes to the remote repository
git push origin develop
# Create and switch to a new branch for the release
git checkout -b release/v1.0.1
# Stage all changes
git add .
# Commit the changes with a message
git commit -m "Prepare release v1.0.1"
# Push the release branch to the remote repository
git push origin release/v1.0.1
# Switch to the main branch
git checkout main
# Pull the latest changes from the remote main branch
git pull origin main
# Merge the release branch into the main branch
git merge release/v1.0.1
# Push the merged changes to the remote main branch
git push origin main
# Create an annotated tag for the new release
git tag -a v1.0.1 -m "Release version 1.0.1"
# Push the tag to the remote repository
git push origin v1.0.1
Updating a Tag with New Changes
If you need to update an existing tag with new changes, here are the steps:
1. Create a new branch from the tag:
# Create and switch to a new branch from the existing tag
git checkout -b update-from-v1.0.1 v1.0.1
2. Make your changes and commit them:
# Stage your changes
git add .
# Commit your changes with a descriptive message
git commit -m "Describe your changes"
3. Push the new branch to remote:
# Push the new branch to the remote repository
git push origin update-from-v1.1.1
4. Update the tag with the new changes:
# Delete the old tag locally
git tag -d v1.1.1
# Create a new tag with the same name and updated changes
git tag -a v1.1.1 -m "Updated release v1.1.1"
# Delete the old tag remotely
git push origin :refs/tags/v1.1.1
# Push the new tag to the remote repository
git push origin v1.1.1
Example Commands in Sequence:
# Create and switch to a new branch from the existing tag
git checkout -b update-from-v1.0.1 v1.0.1
# Stage your changes
git add .
# Commit your changes with a descriptive message
git commit -m "Describe your changes"
# Push the new branch to the remote repository
git push origin update-from-v1.0.1
# Delete the old tag locally
git tag -d v1.0.1
# Create a new tag with the same name and updated changes
git tag -a v1.0.1 -m "Updated release v1.0.1"
# Delete the old tag remotely
git push origin :refs/tags/v1.0.1
# Push the new tag to the remote repository
git push origin v1.1.1
I hope my blog helps make your development process smoother!
希望我的博客能幫助您開發順利!