Django for ISchoolers: Difference between revisions

imported>Aldeka
imported>Aldeka
Line 126:
== Using version control ==
 
Before we do anything else, let’s savecommit our work. We'll be doing this with a piece of version control software called '''git'''.
 
What's this version control nonsense? Well, you probably know the value of saving your work. When writing an important term paper, you want to "Save early, save often" to make sure you don't lose your work if your computer crashes or something else bad happens! But most paper-writing software isn't very good at saving your history--if you decide to delete a section of your paper, save it, and then later decide that you want that section back, most document writing software doesn't have any way of helping you do that. There's only one saved version of the paper (unless you save multiple copies over time, yourself, by hand).
 
Programmers often have to go back into the history of a program to change things--whether it's to diagnose a bug or redesign how a feature works. Programmers also have to have an easy way of being able to edit the same application at the same time, and to share their edits with each other. Thus, besides '''saving''' their work the normal way, programmers '''commit''' their code using version control software.
 
Each commit is a checkpoint in time, containing the '''diff'''--the "difference", all of the changes you made to your code base -- between that commit and the commit before it. Different branches in git share the commits made prior to the branching-off point, then each have their own commit history.
 
* To make a commit, first type <code>git status</code> into your terminal. This will let you know what changes git has noticed in your code and which of those changes, if any, are staged and ready to be committed.
 
<code>$ git status<br>
# On branch my-chunk-1
#
# Initial commit
#
# Untracked files:<br>
# (use "git add <file>..." to include in what will be committed)
#
# __init__.py<br>
# manage.py<br>
# settings.py<br>
# urls.py<br>
nothing added to commit but untracked files present (use "git add" to track)</code>
 
"Untracked files" means that git has noticed some new files inside its folder, but you haven't told git explicitly that you want it to "listen" for, and track, changes in those files.
 
* Add one file: <code>git add manage.py</code>. What does git status say now?
* Add all the files to the repo, in the local directory:
 
<code>$ git add *.py # all .py files, using a wildcard match.</code>
 
What does git status say now?
 
* git commit to commit those files:
 
<code># -m -> what is the 'message' for the commit<br>
git commit -m "Initial commit of Django project from the IOLab Django workshop"</code>
 
* Look at your changes with <code>git log</code> to see your history. Is your commit message there?
 
Huzzah! We committed our changes so far. Now let's make some more changes!
 
== Set up settings ==
Anonymous user