2

I have done some updates on a branch and merge it to master. But it seems I've done a mistake, and I do not know how to fix it.

git log --all --decorate --oneline --graph give this :

*   85b7966 (HEAD -> master, origin/master, origin/HEAD) Merge pull request #2 from doom-fr/improve-documentation
|\  
| * 547f135 (origin/improve-documentation) Improve documentation : add linux installation instructions
|/  
*   66dac19 Merge pull request #1

I think that (origin/improve-documentation) should not be there.

How can I remove it ?

doom
  • 3,276
  • 4
  • 30
  • 41

3 Answers3

2

What you described and what your git log command shows makes perfect sense.

origin/improve-documentation marks where the improve-documentation branch has been pointing to on your remote repository, the last time you connected to it with a git command.

If you want it to disappear you need to ensure 2 things:

  1. The improve-documentation branch must be deleted on GitHub (or what else remote repo you are using)
  2. When updating your local master branch again, use git pull --prune to tell git to discard all local pointers to remote branches which do not exist anymore (this is not done by default).

As explained in Automatic prune with Git fetch or pull you can also make pruning the default behavior locally for your specific remote via

git config remote.origin.prune true

or globally for every git repo you use

git config --global fetch.prune true
gessnersn
  • 21
  • 1
  • 4
  • 1
    To make pruning the *default* default (for everything), use `git config --global fetch.prune true`. Configuring locally for one remote only configures that one remote for that one repository. (This is of course fine, if that's what you want!) – torek Dec 16 '20 at 03:21
1

If i understand it correctly ,you want to undo the commit 547f135 (origin/improve-documentation) that was merged to master branch.

Create a branch off of masterand run git revert <commit-hash>. This will create a new commit and undo all the changes that were done as part of the wrong commit.

You can identify the commit hash by git log

So you can do

git revert 547f135

and then try to merge this branch again to master.

Dev-vruper
  • 421
  • 3
  • 12
0

A slightly sketchy option would be to simply reset master. Only do this with the knowledge and consent of other people using origin!

git switch master  # if necessary
git reset 66dac19
git push -f

This will leave 85b7966 as an orphaned commit that will eventually be garbage-collected. It will also confuse anyone who has already seen 85b7966 and is unaware of what you have done, hence the warning in bold.

chepner
  • 497,756
  • 71
  • 530
  • 681