how to merge to a local branch after checking out to a previous commit

I am working on a local branch VISS. Then I decided to check out a previous commit:

git checkout 98ea3c8042c39e

  • Move commits from master onto a branch using git
  • Managing files through Git that will never be committed
  • Is there an upper limit to the number of commits a git repository can handle?
  • Which SCM/VCS cope well with moving text between files?
  • git fatal:No tags can describe <sha1 number>
  • Git commit list
  • I made some important changes to the code. and then I committed again.

    Now I need to go back to my branch VISS keeping these changes.

    What should I do if I want to:

    1. Go back to my VISS branch discarding what was done before checking out to a previous commit (98ea3c8042c39e).

    2. Go back to my VISS branch merging the new changes with what I had done on the top of the VISS.

  • IntelliJ error: branch 'origin/HEAD' does not point at a commit, some refs could not be read
  • How to create a git clone with branches of a “subproject”?
  • EC2 can't SSH into github
  • How do I create a git repository on our shared server?
  • Automatic Website Deployment with Git and Sbt
  • How to synchronize fork with original GitHub project?
  • One Solution collect form web for “how to merge to a local branch after checking out to a previous commit”

    1. Go back to your branch and discard everything :

      git checkout VISS

      Your new commit atop 98ea3c will be left floating in the middle of nowhere, and will eventually be garbage collected by git.

      Conversely, if you are willing to make 98ea3c the top of VISS and discard what VISS is currently pointing to, do the following:

      git checkout VISS
      git reset --hard 98ea3c
    2. Go back to VISS and merge your new changes on the top of it:

      # On the new commit you just made:
      git rebase VISS
      # Now take note of what the commit ID is.  Assume I got "abc123"; then:
      git checkout VISS
      git merge abc123

      You’ll now have VISS with the change as the latest commit, and no merge commit.

    Git Baby is a git and github fan, let's start git clone.