0

I recently took over the development of a Python/ Django project, where Git is used as the version control for software maintenance and releases etc.

Having not used Git much at all before, I am still getting used to how to use it to manage version control effectively.

I recently pushed some changes to the server to fix a particular bug- this bug has now been fixed, and the feature is working correctly on the live version of the software.

However, when merging the branch on which I had been developing with the master branch, I needed to reset to an old version of the code as I managed to break my local master branch.

Now, having pushed my local master to the server, with the fix for this bug implemented, it seems that I have broken another page on the server- there were some issues with this page a month or so ago, which I fixed at the time, and the reset that I performed on my local master was to a version that was last modified a few days ago, so this bug should not have been in the version that I reset to, but somehow this seems to have broken this other page, even though it was working prior to pushing the most recent bug fix to the server.

I have several branches on my local machine, so tried checking out an old one, where I know that this page still works- and having browsed to it on my local server, I can see that it does.

I then ran a git diff master exportAddsOmits, where exportAddsOmits is the name of the old branch on which the broken page is still working. This command has produced the following output:

 (moon) user:moon user$ git diff master exportAddsOmits
diff --git a/buying/views.py b/buying/views.py
index 08d2fd6..b2f8fe6 100644
--- a/buying/views.py
+++ b/buying/views.py
@@ -651,10 +651,7 @@ def order(request, supplier_id):
            # project = Project.objects.get(id=request.GET.get('project'))
            order_form.initial['project_raw'] = request.GET.get('project')

 -       #project_choices = OrderItem.NON_PROJECT_CHOICES+[('', '-----')]+[(project.id, project.project_name) for project in Project.objects.filter(archived=False, detailed_status=Project.ds9).order_by('project_name')]
-       #(23/11/2016 @ 1110) Add 'Deposit Received' projects to drop down in 'Item Project':
       project_choices = OrderItem.NON_PROJECT_CHOICES+[('', '-----')]+[(project.id, project.project_name) for project in Project.objects.filter(archived=False, detailed_status=Project.ds9).order_by('project_name')]+[(project.id, project.project_name) for project in Project.objects.filter(archived=False, detailed_status=Project.ds8).order_by('project_name')]
-
 +       project_choices = OrderItem.NON_PROJECT_CHOICES+[('', '-----')]+[(project.id, project.project_name) for project in Project.objects.filter(archived=False, detailed_status=Project.ds9).order_by('project_name')]
    top_category_choices = [('', '')] + [(cat.id, cat.name) for cat in Category.objects.filter(parent__isnull=True).distinct().only('name')[:10]] + [('OP', 'Office Purchase')]


 diff --git a/costing/models.py b/costing/models.py
index 5b78684..d845da7 100644
--- a/costing/models.py
+++ b/costing/models.py
@@ -732,12 +732,8 @@ class Deposit(models.Model):
    def adjust_payment(self):
            p = Payment.objects.get_or_create(project=self.project, is_booking_deposit=True)[0]
            p.date_paid = self.date_received
-               print "p.date_paid has been set to self.date_received in Deposit.adjust_payment (costing/models.py)"
            p.amount_exc_vat = self.amount_exc_vat
-               #p.deposit = self.deposit
-               # ERF(21/11/2016 @ 1645) Try adding a line for date_received
-               #p.date_received = self.date_received
-               #print "p.date_received is being set to self.date_received in costing/models.py (line 739): %s " % p.date_received
+               p.deposit = self
            p.save()

         def __str__(self):
 diff --git a/costing/templates/costing/adds_omits.html b/costing/templates/costing/adds_omits.html
index 4d28188..a33fde5 100644
--- a/costing/templates/costing/adds_omits.html
+++ b/costing/templates/costing/adds_omits.html
@@ -24,12 +24,6 @@

What I'm not sure is how to interpret this... There are a number of lines beginning with either + or -, which I understand to be the diff command showing me lines that exist in the first branch, but not in the second, or lines that don't exist in the first branch, but do in the second... but I don't know which way round this is...

Are the lines beginning with - lines that exist in the first branch that I gave the diff (i.e. master), but not the second (i.e. exportAddsOmits) and lines beginning with + lines that don't exist in the first branch (master), but do in the second (exportAddsOmits), or is it the other way around?

Will I need to resolve these differences manually, or can I merge the old branch (exportAddsOmits) with my master branch? If I do merge, is this likely to undo the fix that I have just implemented?

Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118
  • Your diff output looks like a *combined diff*. Are you in the middle of a conflicted merge? (What is the output from `git status`?) – torek Jan 05 '17 at 18:51

2 Answers2

1

Each diff is for each file that are not the same in both branches

The - lines show you the lines that were removed from this file in the first branch and are not in its second branch version

the + lines show you wich lines were added to the file from the second branch and were not in its first branch version

the way it works is every time you change a line of a file it will generate a - and a + like it removed the old line and added a new one even if you changed just one character in the line.

Unprefixed lines are just unchanged and there for context

hope that helps

Mawcel
  • 1,967
  • 15
  • 22
  • So `-` lines currently only exist in the first branch (`master`), and `+` lines currently only exist in the second branch (`exportAddsOmits`)? There appear to be three files which differ between the two branches, with a list of `+`'s & `-`'s for each – Noble-Surfer Jan 05 '17 at 13:48
  • The lines at the start of each `diff` show: `diff -- git a/.../views.py b/.../views.py`, etc, so presumably `a` is the first branch that I passed to the `diff`, i.e. `master` & `b` is the second branch that I passed to the `diff`, i.e. `exportAddsOmits`? – Noble-Surfer Jan 05 '17 at 13:50
  • About the branches that is exactly it – Mawcel Jan 05 '17 at 14:56
  • So I've tried switching to `master`, and adding the lines from `exportAddsOmits` that were missing, and commenting the lines that had been removed, but when I now try clicking the button that calls this `view` (the `view` that displays the page that was broken since I pushed the bug fix to the server), that page is still broken... The error page says: `NoReverseMatch at costing/id/adds_omits/`, which says: `Reverse for 'export_csv' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'costing/(?P[0-9]+)/export-csv/$']` – Noble-Surfer Jan 05 '17 at 15:17
  • The 'Traceback' shows that the issue is in `costing/views.py` in the line: `return render(request, 'costing/adds_omits.html', context) `... but I can't see what the issue is... any suggestions? – Noble-Surfer Jan 05 '17 at 15:21
  • The error page says: `Reverse for 'export_csv' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'costing/(?P[0-9]+)/export-csv/$']` just under where it says: `Error during template rendering`... so I'm wondering if there is an issue with one of the URL patterns somewhere or something? – Noble-Surfer Jan 05 '17 at 15:32
  • Sorry but as i don't use python i definitely cannot help you on the error. – Mawcel Jan 05 '17 at 15:59
  • what i can say is if the changes you need are in exportaddsOmits whatever the situation you should be doing: `git checkout master` then `git merge exportAddsOmits`. Git will know how to merge it and if it doesn't you will end up with a classic merge conflict that you need to solve yourself https://githowto.com/resolving_conflicts – Mawcel Jan 05 '17 at 16:02
  • If I `git checkout master`, and then `git merge exportAddsOmits`, git tells me that it is already up-to-date... but running a `git diff master exportAddsOmits` shows a number of differences between the two branches... – Noble-Surfer Jan 05 '17 at 16:18
  • There will be quite a large number of differences, since the `exportAddsOmits` branch is quite an old one.. – Noble-Surfer Jan 05 '17 at 16:19
  • It looks weird if the diff shows differences the branches have differences so you shouldn't get that message from the merge.Maybe take a look here [http://stackoverflow.com/a/9834872/5758328] . Maybe you are comparing your branches the wrong way around – Mawcel Jan 05 '17 at 16:32
  • I don't understand your last comment...? To clarify: while on `master`, I ran `git merge exportAddsOmits`, and Git produced the output: `Already up-to-date.` I then ran `git diff master exportAddsOmits`, and Git produced output in the form of a long list of differences between the two branches- I actually had to type `q` to quite the `diff`, as the list was too long to scroll to the bottom... This is what I don't understand: How can Git tell me that it is already up-to-date when I try to merge an old branch into `master`, if it then tells me that there are lots of differences between the two? – Noble-Surfer Jan 05 '17 at 16:32
  • The `diff` I ran was `git diff master exportAddsOmits`, while I was on the `master` branch- I'm fairly sure that is the right way round? – Noble-Surfer Jan 05 '17 at 16:34
  • Look at the link i sent you there are several ways of comparing branches – Mawcel Jan 05 '17 at 16:52
1

No matter what you use git diff master exportAddsOmits (- for master branch files, + for exportAddsOmits branch files) or git diff exportAddsOmits master (- for exportAddsOmits branch files, + for master branch files), git will gives you similar output with many difference. Because git diff command gives files difference between two branches. We do sure, files in the two branches are different, so both of the two commands should have output.

When you ran git merge exportAddsOmits, it showed already up-to-date. That is caused by the commit histories between two branch, just like

A---B---C---D              exportAddsOmits
             \
               E---F---G   master

So you should compare the two branches commits difference not files difference. You can use git log exportAddsOmits..master, there will show the commits in master branch but no in exportAddsOmits branch. And git log master..exportAddsOmits will has no output, because exportAddsOmits is older (or we call the parent) than master branch.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74