-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathGIT_Day 02.txt
127 lines (80 loc) · 3.52 KB
/
GIT_Day 02.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
GIT_Day 02
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Git Stages
----------------------
1. Working directory/area ---> This is the place where we write the code
2. Staging area ---> When the files are added to the staging area, git will track the files
3. Repository area ---> This is a local repo where the tracked files will get stored
Git workflow
-------------------------
Working directory ----> Initialize the git (git init) ----> Write the code/Create the files ----> Add the files to staging area (git add) ----> Send the files to local repo area (git commit) ----> Push the files to remote repo. (git push)
Working with git
-----------------------
1. Create a folder in any drive of your PC
2. Open git bash terminal
3. Create a file
4. Check the status of the file (File name will be in red colour, which means git is not tracking them)
5. Track/Add the file to the staging area
6. Verify the status of the file (File name will be in green colour, which means git is tracking those files)
7. Commit the files to local repo area
8. Verify the file status (working tree clean)
Git commands
------------------------
The commands in git are divided into 2 categories;
1. Porcelean commands ---> High level commands ---> Used most commonly
2. Plumming commands ---> Low level commands ----> Based on the requirement
To see the list of all git commands
git help -a
To come out of the commands; press q
To see the details/information related to specific command
git help <CommandName> ---> The browser will open and will give the details about that command
To remove the existing credentials
git config --global --unset user.name
git config --global --unset user.email
To see the list of user names and email ids configured
git config --list --show-origin
To come out of the commands; press q
To change the file name;
git mv <OldFileName> <NewFileName>
To see the commit history
git log
To come out of the commands; press q
To see the commit history in a single line;
git log --oneline
To see the history of a specific commit;
git show <CommitID>
Note: Commit id is of 40 characters length
To see the specific commits from the latest;
git log -<GiveNumber>
Ex: git log -3 ----> It will display the latest 3 commits
To see the commit history in reverse order
git log --reverse
To see the commit history in reverse order in a single line
git log --oneline --reverse
To see the top commits;
git show HEAD
To delete a file
git rm <FileName>
--------------------------------------------------
To recover a deleted file
Assignment
--------------------------------------------------
To see the hidden files/folders
ls -la
To delete the .git folder
rm -rf .git
It is not recommended to delete the .git folder
To unstage a staged file;
git rm --cached <filename>
When the file is unstaged, to remove the changes in the file;
git restore <filename>
To know the author details;
1. of a specific file ----> git blame <FileName>
2. email of a specific file ----> git blame -e <FileName>
To skip the staging area and directly commit the file
git commit -am "text file"
This is not a recommended approach
To see the status of a file in a shortform
git status -s
=> If you see ?? in red colour, it means the file is not tracked by git
=> If you see A in green colour, it means the file is tracked by git