0

This is my Git status.

enter image description here

Because of some weird reason, master and task-e branches are broken. They can't be build now.
Only 6f374ed94ad7f04b1f7a2ca2019374bb7785d9e6 commit is valid. enter image description here

I would like to make this commit to lastest commit of master branch. How do I do?

Benjamin
  • 10,085
  • 19
  • 80
  • 130

2 Answers2

1

It's not completely clear from your question, but I assume that what you want is to add a new commit whose source code is exactly the same as at the older commit, 6f374ed9. (In other words, you want to avoid rewriting history, since obviously master and task-e have been pushed to GitHub.) This takes a few steps in git, which are described in this question. To summarize that, firstly make sure that you have no uncommitted changes (i.e. git status is clean). You would then need to do:

# Switch to the branch you want to add the commit to:
git checkout master
# (... you can merge the result to the other branch later)

# Move the master branch back to the earlier, good commit, forcing the
# working tree and the index to match:
git reset --hard 6f374ed

# Use git reset --soft to point the master branch back to where it was
# originally, but leave the working tree and index as they were at 6f374ed
git reset --soft HEAD@{1}

# Commit the result:
git commit -m "Reverting state back to 6f374ed9"

Then, to update task-e as well, you can do:

git checkout task-e
git merge master
Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
0

You could use git reset, but it would rewrite history that has already been pushed publicly, so it's not advised. I'd use git revert : it allows you to revert a commit, ie. it creates a commit that does the opposite of a commit. That way, you can cancel your commits and get back to the state you want, without rewriting history.

ksol
  • 11,835
  • 5
  • 37
  • 64