git - creating branch just for merge -


*this 1 of "is idea?" questions can't format acceptable question but....

i'm still not 100% comfortable git, merging remote branches. if things go wrong or want give on bunch of merge conflicts, i'm struggling roll merges/commits. find myself farther down rabbit hole speak. i'm wondering, easier create branch remote merge on , locally merge temp branch "real" branch"? way nuke temp branch if went wrong.

update: i'm interested in when remote branch add bunch of files repo. example (using peter's example below):

i this:

$ git init initialized empty git repository in /path/to/repo/.git/ $ touch readme $ git add readme $ git commit -m 'initial commit' [master (root-commit) da9886d] initial commit  0 files changed  create mode 100644 readme $ touch $ git add $ git commit -m 'add a' [master 3480a5b] add  0 files changed  create mode 100644 $ git push // pushed remote (only single file, a) 

then developer this:

$ git clone $ touch b $ git add b $ git commit -m 'add b' [foo 9912a23] add b  0 files changed  create mode 100644 b $ git push // pushed remote (now has 2 files , b) 

if this:

$ git pull 

i'll have 2 files , b. if want "step back" , undo merge:

$ git reset --hard master@{...} 

file b still exist on machine untracked file, right? how can step , remove these files if never did git merge?

this why hoping create separate branch. if create separate branch merge:

$ git checkout -b tempbranchformerge $ git pull 

i still end files , b exist on tempbranchformerge. if things go wrong, should able this:

$ git checkout master $ git branch -d tempbranchformerge 

right? delete file b.

that's absolutely fine, unnecessary.

git tracks history of branches move can access git reflog. particularly git reflog <branch name>.

let's try example. here's bunch of commands setting example. i've got master , foo branch. each has 1 commit. merge foo master.

$ git init initialized empty git repository in /path/to/repo/.git/ $ touch readme $ git add readme $ git commit -m 'initial commit' [master (root-commit) da9886d] initial commit  0 files changed  create mode 100644 readme $ touch $ git add $ git commit -m 'add a' [master 3480a5b] add  0 files changed  create mode 100644 $ git checkout -b foo head~1 switched new branch 'foo' $ touch b $ git add b $ git commit -m 'add b' [foo 9912a23] add b  0 files changed  create mode 100644 b $ git log --decorate --graph --all --pretty=oneline --abbrev-commit * 9912a23 (head, foo) add b | * 3480a5b (master) add |/ * da9886d initial commit $ git checkout master switched branch 'master' $ git merge foo merge made 'recursive' strategy.  0 files changed  create mode 100644 b $ git log --decorate --graph --all --pretty=oneline --abbrev-commit *   d4d06ce (head, master) merge branch 'foo' |\ | * 9912a23 (foo) add b * | 3480a5b add |/ * da9886d initial commit 

now let's suppose wanted undo merge commit, put master whatever before commit.

$ git reflog master d4d06ce master@{0}: merge foo: merge made 'recursive' strategy. 3480a5b master@{1}: commit: add da9886d master@{2}: commit (initial): initial commit $ git reset --hard master@{1} head @ 3480a5b add $ git log --decorate --graph --all --pretty=oneline --abbrev-commit * 9912a23 (foo) add b | * 3480a5b (head, master) add |/ * da9886d initial commit 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -