GIT

git --version
 git version 1.7.9
git clone https://github.com/bmwieczorek/my-git.git
git config --global user.name "Bartosz Wieczorek"
git config --global user.email "... email ..."
cd my-git
git status
On branch master
nothing to commit (working directory clean)
echo "xxx" > x.txt
git status
On branch master
Untracked files:
(use "git add ..." to include in what will be committed)
x.txt
 nothing added to commit but untracked files present (use "git add" to track)
git add x.txt
git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: x.txt
git commit -m "added new x.txt file" x.txt
 [master 96ec6d5] added new x.txt file
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 x.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
nothing to commit (working directory clean)
echo "yyy" > y.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Untracked files:
(use "git add ..." to include in what will be committed)
y.txt
 nothing added to commit but untracked files present (use "git add" to track)
git add y.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: y.txt
echo "111" >> y.txt

Working copy has now 2 lines: yyy and 111; stage area has 1 yyy line so git commit now would only add yyy but not 111; need to git add y.txt to include 111 change in the next commit

git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: y.txt
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: y.txt
git diff y.txt #current working vs stage area (last git add)
diff --git a/y.txt b/y.txt
index 0b20aea..ff129db 100644
--- a/y.txt
+++ b/y.txt
@@ -1 +1,2 @@
yyy
+111
git diff --staged y.txt # repository code vs stage area (last git add), change to commit
diff --git a/y.txt b/y.txt
new file mode 100644
index 0000000..0b20aea
--- /dev/null
+++ b/y.txt
@@ -0,0 +1 @@
+yyy

changing commit message

git commit -m "z with 111" z.txt
 [master 4594649] z with 111
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 z.txt
git log
 commit 47c6adcda9ab8757b6b45a2ef0938cf5931f4a22
 Author: Bartosz Wieczorek
 Date: Wed Aug 13 13:17:45 2014 +0200
z with 111
git commit --amend -m "updated message: z.txt with 111 from command line"
 [master fccdba3] updated message: z.txt with 111 from command line
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 y.txt
 create mode 100644 z.txt
git log
 commit be3af78ba1db23a58c580aea7bba296fc7a4d490
 Author: Bartosz Wieczorek
 Date: Wed Aug 13 13:17:45 2014 +0200
updated message: z.txt with 111 from command line

Reverting local changes (lost forever)

cat a.txt
 a
 b
echo "c" >> a.txt
cat a.txt
 a
 b
 c
git checkout -- a.txt
cat a.txt
 a
 b

Git stash

echo "aaa" > aaa.txt
echo "bbb" >bbb.txt
git add aaa.txt
git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: aaa.txt
Untracked files:
(use "git add ..." to include in what will be committed)
bbb.txt
echo "ccc" > ccc.txt
git add ccc.txt
git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: aaa.txt
new file: ccc.txt
Untracked files:
(use "git add ..." to include in what will be committed)
bbb.txt
git commit -m "added aaa.txt" aaa.txt
 [master feaf44a] added aaa.txt
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 aaa.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: ccc.txt
Untracked files:
(use "git add ..." to include in what will be committed)
bbb.txt
echo "123" >> aaa.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: ccc.txt
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: aaa.txt
Untracked files:
(use "git add ..." to include in what will be committed)
bbb.txt
git stash
 Saved working directory and index state WIP on master: feaf44a added aaa.txt
 HEAD is now at feaf44a added aaa.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Untracked files:
(use "git add ..." to include in what will be committed)
bbb.txt
 nothing added to commit but untracked files present (use "git add" to track)
rm bbb.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
nothing to commit (working directory clean)
git stash list
 stash@{0}: WIP on master: feaf44a added aaa.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
nothing to commit (working directory clean)
git stash apply
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: ccc.txt
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: aaa.txt
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: ccc.txt
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: aaa.txt
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s