2

Here is the story

  1. I got branch named fts from remote repo origin/fts
  2. I've done some commits to local repo fts (without pushing)
  3. I find I commited something I cannot make public
  4. I checkout to last safe commit and get You are in 'detached HEAD' state. message
  5. I've done new commit.

The logs look like that (without some commits)

$ git log --pretty=oneline --abbrev-commit --decorate --all --graph -10 * 3e39eeb (HEAD) That should be pushed as origin/fts | * f38e892 (fts) That cannot be pushed |/ * 84fa79a (origin/fts) Commit i got from remote 

What should I do to

  1. Not push commits from current local fts (f38e892) to remote.
  2. Save this unfortunate branch with different name like private-fts
  3. Move the branchname fts to current detached HEAD (3e39eeb) without any rebasing or merging that would incorporate commits from current fts.
  4. Push current detached HEAD as fts (to become origin/fts).
  5. When I'm sure private-fts is not needed, get rid of it from local repo either.
1
  • Is what you can't make public isolated to just one commit? Commented Dec 14, 2015 at 16:41

3 Answers 3

1

First off, you'll want to rename the fts branch to private-fts using the following command:

git branch fts -m private-fts 

Now, recreate the fts branch at 3e39eeb

git checkout 3e39eeb -b fts 

Push & associate the new fts branch to origin:

git push --set-upstream origin fts 

Once you're ready to remove private-fts alltogether, do:

git branch -D private-fts 
Sign up to request clarification or add additional context in comments.

Comments

1

I would do the following:

  1. Checkout to private-fts from your current fts branch. git checkout -b private-fts, so all of your current code will be saved in private-fts branch.
  2. Remove fts branch. git branch -D fts
  3. Switch back to private-fts branch.
  4. Checkout to your commit, you wish to push to origin/fts
  5. When you are in detached HEAD, switch to fts branch. git checkout -b fts

Now all of your needed code will be in fts branch, and the unfortunate ones in private-fts

Comments

0

If you want to reset your local fts back to what's in origin/fts you can do a hard reset to the commit in origin.

git reset --hard origin/fts 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.