cd my_project
git init .
git add . # add everything
git commit -m 'Initial commit'
... make some changes ...
git add . # adds all changed files to the stage to be committed
git commit -m 'Some changes'
git push origin master
... make some more changes ...
git add index.html css/screen.css # only add these two files to the stage
git commit -m 'Changed index and screen'
git log
git remote add origin git://server/my_project.git
# git remote add origin file:///path/to/local/repositories/my_project.git # For a local (disk) repository
... and push your changes to it ...
git push origin master
-
Write some content to index.html
echo "Hello" > index.html cat index.html # => Hello
-
Commit the new index.html
git add index.html git commit -m 'Hello index.html'
-
Overwrite the original content
echo "Oops" > index.html cat index.html # => "Oops"
-
Restore the original index.html from the repository
git checkout index.html $ cat index.html # => Hello
Assuming the following project:
mkdir -p my_project my_project/images my_project/css my_project/js
echo "<p>Hello World</p>" > my_project/index.html
touch my_project/js/application.js my_project/css/screen.css
cd my_project
Create a repository, and commit initial files.
git init .
git add .
git commit -m 'Initial commit'
Change and add files.
echo "<p>The world has changed.</p>" > index.html
git add index.html
index.html
is now staged. This is a middle-ground between the repository and your working copy. A staged file is not yet committed to the repository, but is independent of any further changes to your working copy.
What this means is that you can continue working on index.html, but still commit the previously staged version:
Commit staged files to the repository...
git commit -m 'Changed content of index.html'
...or re-add your changed working copy
echo "<p>It changed again</p>" > index.html
git add index.html
git commit -m 'Changed content of index.html'
Keep up the good work.