GIT Fundamentals:
Three states in gits:
=> working area
=> Staging area
=> Local repo
To check the status:
=> git status
To configure a folder as a working area:
=> $ git init
Initialized empty Git repository in C:/Users/a42983729/Desktop/Ganesh_cloud/Ganesh-git/.git/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ ls -a
./ ../ .git/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
NOTE: ".got" is memory of git dont mess with that.
If you want to add a folder into git:
=> first create folder physically
=> i have created a folder with the name "src" and then checked the status.
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
Note: Git will never give importance to empty folders.
=> Now i have created a file inside "src" folder with the name "message.txt".
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=> If you want "src" folder to staging area, need to add with folder name. Then it will add all files inside that folder automatically.
$ git add src
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: src/message.txt
=> Now you want to add to local repo from staging with message.
$ git commit -m "added source folder to repo"
[master (root-commit) 4044ac0] added source folder to repo
Committer: Pathri <raja.pathri@t-systems.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 src/message.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git log
commit 4044ac0343b34ba71919f13695495f67b5392833 (HEAD -> master)
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:43:05 2019 +0800
added source folder to repo
==============================================================
=> Now i m going to add one file physically and then will add into git from scratch :
Here i have added a file "first.txt" physcially and then i will check the status its this file will be in "untracked file" list .Once you add it will move to stagging area then you need to do commit.
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
first.txt
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git add "first.txt"
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: first.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git commit -m "first file added"
[master ce9e37e] first file added
Committer: Pathri <raja.pathri@t-systems.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 first.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
===============================================================
NOTE : In git for every version you don't get version id but you will get commit ID.
$ git log
commit ce9e37e00f3f9d1a3f333330b52dfba2215d9956 (HEAD -> master)
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:47:28 2019 +0800
first file added
commit 4044ac0343b34ba71919f13695495f67b5392833
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:43:05 2019 +0800
added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
=> To see shorter format need to use "git log --oneline"
$ git log --oneline
ce9e37e (HEAD -> master) first file added
4044ac0 added source folder to repo
==================================================================
##########################################################################
==================================================================
As of now we did one one change.Now we will make more than one change and then will do commit.
=> first i will create one new folder "TEST" and then will create new file "main.java" inside that folder
=> And then i will create same file name in different folder "SRC". Now we have same filenames in both folders (SRC,TEST).Did some changes in oldfile "messgae.txt" insdie "SRC" folder.
=> Now i will change some content in my file "first.txt" . Which is available outside of both folders.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: first.txt
modified: src/message.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/main.java
test/
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=====================================================================
NOTE: (Untracked files) Means new changes that has made to working directory whcih was never part of Working directory.
=> If you want add more than one at a time with -A.(This one will add modified and untracked files and folders)
=> If you want add only mideified changes with -U
$ git add -A
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: first.txt
new file: src/main.java
modified: src/message.txt
new file: test/main.java
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=> Now you have move from staging to local repo.
$ git commit -m "add test cases"
[master 6712355] add test cases
Committer: Pathri <raja.pathri@t-systems.com>
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
4 files changed, 2 insertions(+)
create mode 100644 src/main.java
create mode 100644 test/main.java
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git log
commit 671235543b85ee361ed957324c594dd5d207fe45 (HEAD -> master)
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 17:05:26 2019 +0800
add test cases
commit ce9e37e00f3f9d1a3f333330b52dfba2215d9956
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:47:28 2019 +0800
first file added
commit 4044ac0343b34ba71919f13695495f67b5392833
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:43:05 2019 +0800
added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
==================================================================
=> Now i have to remove two changes at a one time.
* from TEST folder inside file "main.java" this one already moved to staging area
* one file from from "SRC" folder which is not moved to staging.
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test/main.java
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/message.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git reset --hard
HEAD is now at 6712355 add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
====================================================================
=> If you want to remove changes from working tree(Not from staging area)
(Here i have updated two files from "SRC" folder and revort back only one file changes.)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main.java
modified: src/message.txt
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git checkout -- src/main.java
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/message.txt
no changes added to commit (use "git add" and/or "git commit -a")
=> If you want remove all changes from one specific folder:
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main.java
modified: src/message.txt
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git checkout -- src
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
====================================================================
=> If you want to remove changes from staging area.
Here i have crated one new file "ganesh.docx" but its not added and i did some changes in "first.txt" file.
If you use "git reset --hard" it will remove only staging area files.
=> This command will remove changes from staging & working tree on (only modified)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: first.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
ganesh.docx
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
$ git reset --hard
HEAD is now at 6712355 add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
ganesh.docx
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
====================================================================
=> If you want to remove un-tracked files from git:
"git clean -fd ."
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
ganesh.docx
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git clean -fd .
Removing ganesh.docx
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=====================================================================
How to know how many commits done:
$ git log --oneline
6712355 (HEAD -> master) add test cases
ce9e37e first file added
4044ac0 added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
=====================================================================
How to specific commit ID(Here it will work like point-in-time recovery to a specific ID):
(Here our head is "6712355".Now we are going back to "ce9e37e"(first file added) commit.
Now here you will loss all the files/folders which are done at "add test case" commit.
$ git log --oneline
6712355 (HEAD -> master) add test cases
ce9e37e first file added
4044ac0 added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ ls -ltr
total 1
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 17:17 test/
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 17:26 src/
-rw-r--r-- 1 EMEA2+A42983729 4266656257 19 Feb 15 17:46 first.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git checkout ce9e37e
Note: checking out 'ce9e37e'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at ce9e37e first file added
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((ce9e37e...))
$ ls -ltr
total 0
-rw-r--r-- 1 EMEA2+A42983729 4266656257 0 Feb 15 17:57 first.txt
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 17:57 src/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((ce9e37e...))
$
$ git checkout 6712355
Previous HEAD position was ce9e37e first file added
HEAD is now at 6712355 add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((6712355...))
$ ls -ltr
total 1
-rw-r--r-- 1 EMEA2+A42983729 4266656257 19 Feb 15 18:08 first.txt
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 18:08 src/
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 18:08 test/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((6712355...))
$ git checkout master
Switched to branch 'master'
===================================================================
=> How to know Master and parents tree details from Commit-ID:
$ git cat-file -p 671235543b85ee361ed957324c594dd5d207fe45
tree 441f2f32578c9e8987f9ac9b6a13cb82da5e4e23
parent ce9e37e00f3f9d1a3f333330b52dfba2215d9956
author Pathri <raja.pathri@t-systems.com> 1550221526 +0800
committer Pathri <raja.pathri@t-systems.com> 1550221526 +0800
add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
=> working area
=> Staging area
=> Local repo
To check the status:
=> git status
To configure a folder as a working area:
=> $ git init
Initialized empty Git repository in C:/Users/a42983729/Desktop/Ganesh_cloud/Ganesh-git/.git/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ ls -a
./ ../ .git/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
NOTE: ".got" is memory of git dont mess with that.
If you want to add a folder into git:
=> first create folder physically
=> i have created a folder with the name "src" and then checked the status.
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
Note: Git will never give importance to empty folders.
=> Now i have created a file inside "src" folder with the name "message.txt".
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=> If you want "src" folder to staging area, need to add with folder name. Then it will add all files inside that folder automatically.
$ git add src
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: src/message.txt
=> Now you want to add to local repo from staging with message.
$ git commit -m "added source folder to repo"
[master (root-commit) 4044ac0] added source folder to repo
Committer: Pathri <raja.pathri@t-systems.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 src/message.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git log
commit 4044ac0343b34ba71919f13695495f67b5392833 (HEAD -> master)
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:43:05 2019 +0800
added source folder to repo
==============================================================
=> Now i m going to add one file physically and then will add into git from scratch :
Here i have added a file "first.txt" physcially and then i will check the status its this file will be in "untracked file" list .Once you add it will move to stagging area then you need to do commit.
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
first.txt
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git add "first.txt"
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: first.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git commit -m "first file added"
[master ce9e37e] first file added
Committer: Pathri <raja.pathri@t-systems.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 first.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
===============================================================
NOTE : In git for every version you don't get version id but you will get commit ID.
$ git log
commit ce9e37e00f3f9d1a3f333330b52dfba2215d9956 (HEAD -> master)
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:47:28 2019 +0800
first file added
commit 4044ac0343b34ba71919f13695495f67b5392833
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:43:05 2019 +0800
added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
=> To see shorter format need to use "git log --oneline"
$ git log --oneline
ce9e37e (HEAD -> master) first file added
4044ac0 added source folder to repo
==================================================================
##########################################################################
==================================================================
As of now we did one one change.Now we will make more than one change and then will do commit.
=> first i will create one new folder "TEST" and then will create new file "main.java" inside that folder
=> And then i will create same file name in different folder "SRC". Now we have same filenames in both folders (SRC,TEST).Did some changes in oldfile "messgae.txt" insdie "SRC" folder.
=> Now i will change some content in my file "first.txt" . Which is available outside of both folders.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: first.txt
modified: src/message.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/main.java
test/
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=====================================================================
NOTE: (Untracked files) Means new changes that has made to working directory whcih was never part of Working directory.
=> If you want add more than one at a time with -A.(This one will add modified and untracked files and folders)
=> If you want add only mideified changes with -U
$ git add -A
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: first.txt
new file: src/main.java
modified: src/message.txt
new file: test/main.java
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=> Now you have move from staging to local repo.
$ git commit -m "add test cases"
[master 6712355] add test cases
Committer: Pathri <raja.pathri@t-systems.com>
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
4 files changed, 2 insertions(+)
create mode 100644 src/main.java
create mode 100644 test/main.java
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git log
commit 671235543b85ee361ed957324c594dd5d207fe45 (HEAD -> master)
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 17:05:26 2019 +0800
add test cases
commit ce9e37e00f3f9d1a3f333330b52dfba2215d9956
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:47:28 2019 +0800
first file added
commit 4044ac0343b34ba71919f13695495f67b5392833
Author: Pathri <raja.pathri@t-systems.com>
Date: Fri Feb 15 15:43:05 2019 +0800
added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
==================================================================
=> Now i have to remove two changes at a one time.
* from TEST folder inside file "main.java" this one already moved to staging area
* one file from from "SRC" folder which is not moved to staging.
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test/main.java
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/message.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git reset --hard
HEAD is now at 6712355 add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
====================================================================
=> If you want to remove changes from working tree(Not from staging area)
(Here i have updated two files from "SRC" folder and revort back only one file changes.)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main.java
modified: src/message.txt
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git checkout -- src/main.java
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/message.txt
no changes added to commit (use "git add" and/or "git commit -a")
=> If you want remove all changes from one specific folder:
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main.java
modified: src/message.txt
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git checkout -- src
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
====================================================================
=> If you want to remove changes from staging area.
Here i have crated one new file "ganesh.docx" but its not added and i did some changes in "first.txt" file.
If you use "git reset --hard" it will remove only staging area files.
=> This command will remove changes from staging & working tree on (only modified)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: first.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
ganesh.docx
no changes added to commit (use "git add" and/or "git commit -a")
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
$ git reset --hard
HEAD is now at 6712355 add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
ganesh.docx
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
====================================================================
=> If you want to remove un-tracked files from git:
"git clean -fd ."
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
ganesh.docx
nothing added to commit but untracked files present (use "git add" to track)
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git clean -fd .
Removing ganesh.docx
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
$ git status
On branch master
nothing to commit, working tree clean
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
=====================================================================
How to know how many commits done:
$ git log --oneline
6712355 (HEAD -> master) add test cases
ce9e37e first file added
4044ac0 added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
=====================================================================
How to specific commit ID(Here it will work like point-in-time recovery to a specific ID):
(Here our head is "6712355".Now we are going back to "ce9e37e"(first file added) commit.
Now here you will loss all the files/folders which are done at "add test case" commit.
$ git log --oneline
6712355 (HEAD -> master) add test cases
ce9e37e first file added
4044ac0 added source folder to repo
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ ls -ltr
total 1
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 17:17 test/
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 17:26 src/
-rw-r--r-- 1 EMEA2+A42983729 4266656257 19 Feb 15 17:46 first.txt
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$ git checkout ce9e37e
Note: checking out 'ce9e37e'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at ce9e37e first file added
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((ce9e37e...))
$ ls -ltr
total 0
-rw-r--r-- 1 EMEA2+A42983729 4266656257 0 Feb 15 17:57 first.txt
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 17:57 src/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((ce9e37e...))
$
$ git checkout 6712355
Previous HEAD position was ce9e37e first file added
HEAD is now at 6712355 add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((6712355...))
$ ls -ltr
total 1
-rw-r--r-- 1 EMEA2+A42983729 4266656257 19 Feb 15 18:08 first.txt
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 18:08 src/
drwxr-xr-x 1 EMEA2+A42983729 4266656257 0 Feb 15 18:08 test/
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git ((6712355...))
$ git checkout master
Switched to branch 'master'
===================================================================
=> How to know Master and parents tree details from Commit-ID:
$ git cat-file -p 671235543b85ee361ed957324c594dd5d207fe45
tree 441f2f32578c9e8987f9ac9b6a13cb82da5e4e23
parent ce9e37e00f3f9d1a3f333330b52dfba2215d9956
author Pathri <raja.pathri@t-systems.com> 1550221526 +0800
committer Pathri <raja.pathri@t-systems.com> 1550221526 +0800
add test cases
EMEA2+A42983729@BAPAA993 MINGW64 ~/Desktop/Ganesh_cloud/Ganesh-git (master)
$
Comments
Post a Comment