经过这么多次的git的操作,现在对这个工具更有深刻的认识了。
Imaging in a work scenes,after you git clone git-project
and you “git checkout -b new_branch”.When you have finished some works,for example,fix bug and orther operations, you are preparing git push origin master
,But :), yes,you will face such scenes like that.
Important: Some people have updated “master branch”,you felt bad because maintainer will not accept your change(There is called confilct).So, you must resolve it first.
How?
Uncommited( undo git push)
If you dont’ t have commited (push) your change(or after git add
),or you git format-patch
this is best scenes.
- In your local branch:
git stash
The command will stash your local work, maybe hint.If you operate the step,the origin master will not note your change,so,
git checkout master
- Or some other branchs:
and
git fetch origin master && git rebase origin master
- Return your local branch
git rebase origin/master
git stash pop
OK
Committed (git push)
In gerrit,there is many cases you have git push
code in gerrit server,but
owner of system maybe not have satisfaction with your change.After servel days,
you have to rebase master branch into you dev branch. This is easy to do it.
- update master branch
Yeah, first of all we must update master branch in any methods.
git fetch origin
First fetch the new master from the upstream repository, then rebase your work branch on that:
- On local branch rebase the master branch
git rebase origin/master