2

I've been working on a website for a client. I'm using Git on Azure DevOps Services. I am working alone on this and although I've done a lot of self-training on git, I'm still a novice. And since I'm working alone, I've not had any chance to practice branching and merging with git. In order to start working on changes that my client wanted done, I branched. Here's a picture of the Commits from my Azure DevOps Repos section for this project:

enter image description here

At commit 5d2abb2d I started making the changes needed. Then at commit 10e7b46c I merged the changes in the feature branch, back into the master branch.

Or at least I thought that's what I did. I issued a git checkout feature branch, did a pull operation, just to make sure I had the latest locally. I saw all the code I put in at 5d2abb2d. But when I did a git checkout master and did another pull, it looked exactly like it did before I branched to the feature branch!

I'm sure I'm doing something wrong. Probably got the wrong idea, but I don't know what I've done wrong nor how to fix it. I'm glad I didn't delete that feature branch! I'm assuming I can, somehow, still get the changes I've made in the feature branch, back into the master branch. How do I do that, please?

Rod
  • 4,107
  • 12
  • 57
  • 81
  • You say you did a `git pull` *operation* but you don't quote the exact command used. That exact command might help here... – torek Aug 18 '20 at 02:28
  • Have you checked the master branch in Azure DevOps Repos? I want to confirm whether the problem is due to failed pull request or failed `git pull` commands. – Jane Ma-MSFT Aug 18 '20 at 06:04
  • I'm sorry, @torek, I've been fighting other issues so didn't see your question until now. When I issued the `git pull` command, that is all I specified for the command. – Rod Aug 24 '20 at 00:41
  • @JaneMa-MSFT good suggestion. I've just checked the code in the Azure DevOps repo. The code in the master branch is wrong. It doesn't have any of the code in the feature branch. I've done the push wrong. I am using VS Code. What did I do wrong with VS Code? If VonC's suggestion is correct, I could try doing that with posh-git. I've never seen the `git switch [branch]` command, so am not sure. – Rod Aug 24 '20 at 00:54
  • Ok, `git pull` with no additional arguments means: *fetch from my upstream repository, then merge with (or rebase on, if configured to rebase instead of merge) my upstream*. So this depends on (a) which branch you are on, and (b) what the upstream is for that branch: the upstream of `master` is typically `origin/master` and the upstream of some feature branch like `feature` is typically `origin/feature`. – torek Aug 24 '20 at 01:51
  • What's not clear here, then, is: who did the merge? Did they run `git push` afterward, to send the merge commit to `origin`? If so, what *name* did they have `origin` update? – torek Aug 24 '20 at 01:51

1 Answers1

0

The usual set of command to "merge back to master" should be:

git switch master
git merge feature
git push

(Note: use git switch rather than checkout, with Git 2.23+) At which point, you should see your feature code in master.
A git log --decorate --oneline --graph --all --branches should show you HEAD at master, with two parents (one commit from master, one from feature)

If it is not the case, the merge itself might have not followed that exact sequence of commands.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • VonC, I looked at the Pro Git book by Scott Chacon and Ben Straub, published by APress. It doesn't mention a `git switch` command. It is the second edition, could that be why it doesn't mention `git switch`? – Rod Aug 30 '20 at 19:51
  • @Rod Yes, the Pro Git book is quite old now. And `git switch` is still considered experimental. But it is quite reliable and considerably more accurate than `git checkout`. – VonC Aug 30 '20 at 20:06