2019年11月21日 星期四
2019年10月30日 星期三
Working while waiting for pending PR
I'm assuming you want to start the new
user_story_2
branch on top of the work you've done in user_story_1
. Here's the workflow I use in this sort of scenario:- Open Pull Request for
user_story_1
:* (user_story_1) * / * (master) * *
- Create new branch
user_story_2
based onuser_story_1
:$ git checkout -b user_story_2 user_story_1
* (user_story_1, user_story_2) * / * (master) * *
- Work on the new branch:
* (user_story_2) * * (user_story_1) * / * (master) * *
- Pull Request gets merged:
* (user_story_2) * * | (master) |\| | * (user_story_1) | * |/ * * *
- Delete old branch:
* (user_story_2) * * | (master) |\| | * | * |/ * * *
- Rebase new branch onto
master
:* (user_story_2) * / * (master) |\ | * | * |/ * * *
from : https://stackoverflow.com/questions/35790561/working-while-waiting-for-pending-pr
2019年9月10日 星期二
2019年9月6日 星期五
Undo a Git merge that hasn't been pushed yet
With
git reflog
check which commit is one prior the merge (git reflog
will be a better option than git log
). Then you can reset it using:git reset --hard commit_sha
There's also another way:
git reset --hard HEAD~1
It will get you back 1 commit.
Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state. To keep them either stash changes away or see
--merge
option below.
As @Velmont suggested below in his answer, in this direct case using:
git reset --hard ORIG_HEAD
might yield better results, as it should preserve your changes.
ORIG_HEAD
will point to a commit directly before merge has occurred, so you don't have to hunt for it yourself.
A further tip is to use the
--merge
switch instead of --hard
since it doesn't reset files unnecessarily:git reset --merge ORIG_HEAD
--mergeResets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added).
from : https://stackoverflow.com/questions/2389361/undo-a-git-merge-that-hasnt-been-pushed-yet
How to revert a merge commit that's already pushed to remote branch?
The
-m
option specifies the parent number. This is because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.
When you view a merge commit in the output of
git log
, you will see its parents listed on the line that begins with Merge
:commit 8f937c683929b08379097828c8a04350b9b8e183
Merge: 8989ee0 7c6b236
Author: Ben James <ben@example.com>
Date: Wed Aug 17 22:49:41 2011 +0100
Merge branch 'gh-pages'
Conflicts:
README
In this situation,
git revert 8f937c6 -m 1
will get you the tree as it was in 8989ee0
, and git revert -m 2
will reinstate the tree as it was in 7c6b236
.
To better understand the parent IDs, you can run:
git log 8989ee0
and
git log 7c6b236
from : https://stackoverflow.com/questions/7099833/how-to-revert-a-merge-commit-thats-already-pushed-to-remote-branch
訂閱:
文章 (Atom)
user_story_2
ontomaster
:git rebase --onto master user_story_1 user_story_2
-- might result in conflicts if the two branches aren't completely independent. – alextercete Dec 22 '16 at 16:36git rebase -i master
, and it should show you a list of commits onuser_story_2
including the earlier commits fromuser_story_1
. Remove thepick
lines for commits fromuser_story_1
, and complete the rebase. – Athyuttam Eleti Feb 25 at 18:00user_story_1
? I guess after that we checkout touser_story_2
and rebase withuser_story_1
? – truongnm Jun 19 at 9:32user_story_1
hasn't been merged tomaster
yet). – alextercete Jun 25 at 8:07