4

I check out a branch named FNB-90 from the master. In the branch FNB-90, I made 2 add, commits and push them to the remote. Then, check out another branch named FNB-90-CHILD from the FNB-90.

a. Now, if in the branch FNB-90, I commend:

$ git fetch  # will fetch the latest changes on the remote
$ git reset --hard origin/master # will set your local branch to match the representation of the remote just pulled down.

will the FNB-90 revert back to the original state that I have checked out? If not, then how to do that?

b. If I delete the branch FNB-90 with the commend,

$ git branch -d FNB-90
$ git push origin --delete FNB-90

What will happen to the branch FNB-90-CHILD i.e. will it become a direct branch of the master?

Arefe
  • 11,321
  • 18
  • 114
  • 168
  • 2
    Branches in git are 'pointers to a "head" node in a *particular* DAG'. Insofar, two different branch names are not related - deleting a name to a commit (see previous) does not affect any other names to that commit or other commits. – user2864740 Feb 14 '18 at 04:59
  • Whats the DAG and can you write a brief answer if time permits? Specially, I need to know how to revert back the `FNB-90` to the original state after the add, commit and push(s) – Arefe Feb 14 '18 at 05:00
  • DAG stands for [Directed acyclic graph](https://en.wikipedia.org/wiki/Directed_acyclic_graph) - basically, no commit can ever be an ancestor (or a descendant) of itself. – user2864740 Feb 14 '18 at 05:01
  • To put back FNB-90 to the original state, force it (`branch -f`) to the appropriate commit where it "should" be; changing remote branches might upset others, but.. The [`reflog`](https://git-scm.com/docs/git-reflog) is usually handy to see where things came from if they were accidentally moved. – user2864740 Feb 14 '18 at 05:06

2 Answers2

1

Answer: a

will the FNB-90 revert back to the original state that I have checked out?

Yes, now origin/master and local FNB-90 are have same commit history. If you want to update origin/FNB-90 then you have to do force push.

N.B. Force push will replace the history of origin/FNB-90 with the history of local FNB-90.

$ git fetch
$ git checkout FNB-90
$ git reset --hard origin/master

$ git push -f origin FNB-90 

Now, origin/master = origin/FNB-90 = local FNB-90 are in same state.

Also, FNB-90-CHILD has no effect for this. (history is same as before)


Answer: b

if you delete the branch FNB-90 from local and remote it will have no effect on FNB-90-CHILD. A branch (HEAD) just a pointer to a commit. If we delete a branch, it deletes the branch's pointer but commit exists yet.

Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
1

will the FNB-90 revert back to the original state that I have checked out?

Yes, provided master did not have commits done locally compared to origin/master.
To be sure to revert, look for the checkout FNB-90 event in the reflog, as seen here.

Note that if you did pushed FNB-90 before, you will have to do a git push --force in order to propagate that reset: make sure your colleagues are aware of that (they will have to reset their own FNB-90 branch)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250