10/19/2023 0 Comments Git delete branch error not y merged![]() The only sensible thing to do with branch2 is to delete it. ![]() After successfully making this new commit. A-B-C-D-E <- branch1 (HEAD)Īnd we run git merge -squash branch2, we'll make a new commit on the current branch branch1 that is the result of combining the diff from C to E-what we did on branch1-with the diff from C to H-what they did on branch2. Commits are historyįundamentally, using git merge -squash is a way to tell Git: I'm going to throw away some commits / history. It's safe to delete the name another-branch as commit C is protected by being on master. It's safe to delete the name new-branch as commit B is protected by being on master. Commits B and C are therefore on branch master, as well as being on branches new-branch and another-branch respectively. From D, Git can walk back to commits A and B. Now each request, to delete the names new-branch and another-branch, would be "safe", because starting at commit E, Git can walk back to commits D and C. ![]() If we'd used regular git merge-with -no-ff the first time, since otherwise Git would have cheated with a fast-forward instead of a merge-we'd have, at this point, this graph: C_ <- another-branch The git branch -d command will refuse to delete it as commit C is not an ancestor of current commit E. The same goes for commit C, find-able only through the name another-branch. Git won't discard the name, and hence lose the commit, unless you force it. Since Git is all about commits, losing a commit would be bad. (Remember, B stands in for some random-looking hash ID that we would never be able to guess.) If we do delete the name new-branch, we will lose commit B. In fact, the name new-branch is the only way we have to find commit B. That's true we will not find B in a walk from E back to the root. What this is telling you is that from commit E-where you are now-there's no way to find commit B. This makes new commit/snapshot E, so let's draw that: C error: The branch 'new-branch' is not fully merged. Since it is a squash-merge, rather than a real merge, once again we do not have a backwards link to commit C, even though we used commit C to do the merge: $ git commit -m "Squash another-branch" The last step here is to commit the merge. (you can substitute whatever you want for the merge result in the here-document section before the END). This creates third commit C, dragging the name another-branch forward to it: C ans This creates new commit B, dragging the name new-branch forward: A > ans The repository now has one named branch, master, which holds the hash ID of this one commit A, so we can draw it like this: A > ans That one commit has some big ugly hash ID, but I'll just use the letter A to stand in for it. You now have a repository with exactly one commit in it. Using your example, creating a new empty repository and stopping at this point: $ git commit -m "First commit" Git isn't really very much concerned about branches either: it's still all about commits. Git isn't really concerned with files, as it's about commits. In particular, if you use a plain git merge (with -no-ff if/when required), Git records the commits. You can get several things that may or may not be good enough. How can I tell whether the branches have been merged? The two branches do not appear in the list of merged branches, so this didn't work either. Trying to use git diff: $ git diff new-branchĪll the statements above yield a non-empty diff. I could use option -D, but usually someone else merges my stuff, and I want to check > If you are sure you want to delete it, run 'git branch -D another-branch'. > error: The branch 'another-branch' is not fully merged. ![]() > If you are sure you want to delete it, run 'git branch -D new-branch'. > error: The branch 'new-branch' is not fully merged. I should be able to delete them now, right? Unfortunately, no: $ git branch -d new-branch $ git commit -m "Commit on another-branch"īoth branches have been merged. To reproduce, create a new git repository: $ mkdir tmpĬreate branch new-branch with commits: $ git checkout -b new-branchĬreate branch another-branch with commits: $ git checkout master How can I quickly check this with existing git commands? To determine whether a branch has been fully merged. When merging branches with -squash, git does no longer seem to be able ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |