Git Work Flow for Non-trivial Tasks
In past, we were often confronted with two issues when dealing with non-trivial tasks (say, big features) since one and only one commit was allowed, and only at the time when the feature was accomplished.
- Hard to track/backup our changes during development.
Most of us would like to be able to make a check point as we made a little progress. That way, had there been anything wrong, we could rollback to previous check point easily. But, since there was only one commit allowed, people had to backup/restore code manually.
- Hard to collaboration in terms of coding
Usually, there were more than one people working on the task and hence the needs to sync changes among teammates. With SVN etc. they have to either share an account and work on the same copy of code or manually distribute and apply changes from each other.
Fortunately, with git, those two issues are no long issues at all. You simply
- Create a branch for the task you are working on.
- On that feature branch, commit as you want.
- Check out the branch into which your feature code should goes
- Then, run
git merge --squash fid-Awhen the feature is done
Later on, whenever you make more modification in the feture branch, you shall redo the merge squash.
- Discard previous merge:
git reset --hard HEAD^on the release branch
- Redo merge squash:
git merge --squash fid-A
- Redo commit:
git commitIf you are using gerrit for code inspection, you shall commit the change with previous commit ID.
- Creating the feature branch on official repository would be the best as the official repository is usually regularly backed-up by IT and accessable by all team members. However, if you are not allowed to do that, you can create the branch locally and have your teammates clone your repository. Thanks to the distribute nature of git, you needn't do anything to setup your local repository for that.
Reference: Understanding the Git Workflow
blog comments powered by Disqus