git - How to merge deteched commits to master -


i tried create new branch commit of master. don't remember command used think 1 (but not sure)

git branch branchname <sha1-of-commit> 

i got new branch bunch of commits. found master branch lost commits found in new branch. changes related lost commits lost in master branch.

it looks detached bunch of commits master new branch. never wanted master branch lost commits. how can restore detached commit master?

please see illustration of problem below:

some random commits detached new branch

so, commit 4, 7, 8, 10 , 13 on new branch , want them in master instead.

you can't move detached head state, command above, you have

git checkout <sha-1 of commit> 

or

git checkout branchname 

so ran commit has messed things, use

git reflog 

to try , find out things went wrong.

however, if ran right command, , can't remember. merge branch master.

1/ checkout commit 13, assuming that's final commit made on detached head state.

git checkout <sha-1 of commit 13> 

2/ give branch name, means give branch name, makes checkout later easier.if run

git branch -a  

you'll this

(detached <sha-1 of commit 13) master *other branches 

to rename branch do;

git checkout -b <branch-name> 

then list branches again

<branch-name> master *other branches 

3/ merging easy now, checkout master branch , merge

git checkout master git merge <branch-name> 

cheers!


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -