-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGit-Notes.txt
367 lines (293 loc) · 13.5 KB
/
Git-Notes.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
*********** GIT ************
Git Index:
==========
* Introduction to git
* Git Terminology
* Repo's
* .gitignore
* log Management
* Branching
* Merging/rebase
* Merge Conflicts
* cherry-pick
* stash
* snapshort
* HEAD
* unstaging(rm, reset, revert)
* Git Diff
* Tags
* bisect
* rewritting commit messages
* git-hub
Git is a Source Code Management(SCM) / Version Control system(VCS) / Distributed version control system
--> Types of SCM/VCS tools
* Git,
* CVS,
* Perforce,
* clearcase,
* svn
git:- it is a process of tracking and controlling/maintaining changes of a software product
--> Download git from https://git-scm.com/
which git --> path of git where it installed
git --version -->to verify
git help config
git features compare to other tools:-
1. Speed
2. Support for non-linear development(thounds of branches, for parallel development)
3. distributed version control system
4. Able to handle large projects efficiently
Why Git is Distributed Version Control system:-
1. Speed
2. Network Issues
3. user collabration
4. security reasons user to user sharing is not recommanded.
Git Terminology:-
=================
1. client/server
2. workspace: - space where the client comm with server
3. Repository : - it is a container/Directory. for each product/project we've one repository in the server.
4. Branch :- parallel development
5. Checkin:- Once the changes done, storing back to the server to maintain perminentaly
6 Checkout:- Taking petmission from server to do modifications.
7. Revision/Version id/commit id : - git will track all the info of changes done by a user like when,which repo,who,which file, what changes)
it stores in the form of snapshots i.e diff b/n existing file data and currently modified file data.
commit id/check in :- with 40 char long
in workspace we've 3 stages before commit id get generated
--> working dir:- where you working with files physically
--> Staging Area:- it helps to create commit id(it is virtual area , here workspace don't know which one is existing and modified data)
--> Repository:- where stores data (commited file)
git config:-
=========
git config --global user.name "TekTeacher"
git config --global user.email "[email protected]
git config --global push.default simple
git config --global core.editor 'vi'
git config --list
local : By default, git config will write to a local level, if no configuration option is passed. .git/config
global : Global level configuration is user-specific, means it is applied to an operating system user.
Global configuration values are stored in C:\Users\vinodh\.gitconfig
Ex:- One of the most common use cases for git config is configuring which editor Git should use.
editor = VIM
Ex:- Merging Tools
git config --global merge.tool kdiff3
system : System-level configuration is applied across an entire machine. This covers all users on an operating system and all repos.
system configuration values are stored in C:\Program Files\Git\mingw64\etc\gitconfig
git config --edit/--list --local
git config --edit --global
git config --edit --system
creating Repositorys:-
1. bare repo: is the centrailized repository which is used to store and share the changes, but we cannot view the data.
2. non-bare repo: user (or) workspace (or) local repository whih is used to modify the changes.
mkdir central.git
git init --bare
git clone central.git <source> vinuspace <dest>
create file in workspace
move to staging area : git add java
move from staging repo : git commit -m "first chickin"
-->git log : list of all the commits will display
--> set of changes together with single version id: git add . (or) java, oracle...etc
if you don't have the same content then-->Modified/Untracked files
if you have same content in the file then --> Unmodified
--> git push <source> <dest>
--> git push enter : to push the changes to repository for sharing to other users
--> 2nd user access the repo and created new file and pushed it to central repo and now
1user want to update things what user2 changed. then use
-->git pull
Git ignoring:
=============
--> .gitignore : is a conf file to ignore the unwanted runtime files like jar, war, log....
1.class (Full name)
*.class (pattern matching)
Log viewing:
============
--> git log -3
--> git log --oneline --grep "workspace"
--> git log --pretty=oneline
--> git log --grep "stringmasg" --oneline
--> git shortlog
--> git log --stat
git show --stat 23rt459bf
git show --name-status 23rt45bf
git show --name-only abc
git log hello.txt
Branching:-
===========
--> parallel development
--> storing of files in a repo is in the form of branches
ex: android windows
file1 file1
file2 file2
here the futures are same only slight diff i.e os
--> master is the default branch whenever we create repository/workspace
--> at any point of time you can work with only one branch at a time
--> git branch : list of branches avilable
git branch branch_name
git checkout new_branch : switch to other branch
git checkout -b new_branch_name : creating new and switching to new branch
--> when we create a new branch based on the master the same fiels and commit ids will come to new branch also.
# merging the 2 branches:-
--> git merge <sour> <dest>
--> git branch -d <branch_name> : to delete branch, use 'D' for forcely remove without fully merged.
--> git branch --merged:- lists the branches that have been merged into the current branch
--> git branch –no-merged:- lists the branches that have not been merged
--> git rebase :Alternate to merge
Note:- when we create,edit,delete in workspace, this shows same in all branches until you commit permanently.
--> bare repo you will not have working dir, so i.e you not able to see
Merging:-
=========
--> Master(Target)<---------feature(source)
cherry-pick
===========
it picks the specific commit-id for merging.
eg:- git cherry-pick a620252dbebc44a63ef8fc3041b5eef82d3089ef
checkout command:-
==================
1. git checkout <BRANCH>:<COMMITID> --> specific commit('detached HEAD')
2. git checkout branch_name --> to switch one branch to another
3. git checkout -b <new-branch-name> --> creating and directly switching to new branch
4. git checkout -- file1 file2 --> to dicard the changes in working directory(when only files deleted,edited from work dir)
Stash::
=======
saving(backup) your un-commited changes and also you can get it back(restore) whenever you want.
git stash save "message" --> it will do 2 things
1. whenever you modifing the changes it will take backup.
2. and it revert back with orginal position of the file where you started.
git stash list --> list all stashes
git stash apply stash@{0} --> to apply(restore) the changes
git stash pop --> it will apply and remove the last stash array[0]
git stash drop --> it will drop the latest one (or) you can specify perticular one also eg:- git stash drop stash@{3}
git stash clear --> remove all backup stashes.
git stash show --> it shows the changes that are there in the stash
file types in git repositories
tracked file --> a file which has been already staged/indexed and committed.
* git stash
untracked file --> a file which has not been already staged or committed.
* git stash -u save "message"
ignored file --> a file which Git has been explicitly told to ignore. (eg:- .gitignore)
* git stash -a save "message"
Removing files:
===============
rm
git rm filename
git clean -n(dry run means which are the file eligible to remove, very care full before running this)
note: removes untracked files
git clean -f( removes the untracked file instead of adding to .gitignore conf file)
Removing files in working Dir:-
===============================
git rm :- will remove the file from the index and working directory ( only index if you used --cached ) -
so that the deletion is staged for next commit.
When using git rm, the removal will part of your next commit. So if you want to push the change you should use git rm
rm:-However, if you do end up using rm instead of git rm. You can skip the git add and directly commit the changes using: git commit -a
Undos
=====
i added a file into staging area, now i want to modify it before going to commit it?
1. git reset (mixed is the default option)
2. git reset --hard --> to remove changes from all the 3 areas
@ working directory
@ staging Area
@ Repository(once file/action arrives to staging area, it creats temperary commit id in commiting area)
3. git reset --soft --> It only removes temp/ref id from commiting/git directory
Undo/Reverting Changes after commiting:-
=======================================
1. git revert 256ed01(1st 7char) --> it revert only the content not the complete entry(commit id) and create a new commit id and refering to previous.
HEAD:-
======
HEAD is the reference to the most recent commit in the current branch(In most of the cases).
HEAD Doesn't point to most recent commit when we go into DETACHED HEAD State.
git show HEAD --> to see head commit
git difftool HEAD HEAD~1
Snapshot
=========
it store difference between the files in the form of snapshort
WD STG
tekteacher tekteacher
---------- -----------
line1 line1
line2 line2
line3 line3 (snapshort)
Tags:-
-------
to identify/reference for a commitid to quick access/ creating specific point in history for our repository
create tag for particular commits:
git tag <tag-name> <reference of commit>
git tag <name-of-tag> --> light weight tag
git tag -a <tag-name> -m "comment" <commitid> --> annotated tag
git tag -n9 --> to see tag messgaes
git tag --> to list tags
git show --stat <tag_name>
git push origin v7.2 ---> pushing to remote(github)
git push origin --tags ---> pushing all tags at once to remote
git push --tags
Note:- when you working in folder in which github repository is cloned)
Deleting tags from local repository:
git tag -d <tag_name>
git tag -delete <tag-name>
git tag -d v7.2 vinumaa v7.3 --> deleting multiple tags at once in local repository
Deleting tags from remote repository:
git push origin -d v7.2
git push origin -delete v7.2
git push origin :v7.2
git push origin -d v7.2 vinumaa v7.3 --> deleting multiple tags at once in remote repositor
we cannot checkout tags in git but, we can create a branch from tag and checkout the branch
git checkout -b <branch_name> <tag_name>(give already created tag names)
Diff:-
======
used to compare Changes,branches,and commits.
git diff --> diff b/n version in the working dir and version in the staging/index area
git diff HEAD --> diff b/n version in working dir and commiting dir
git diff --cached --> diff b/n staging and commit versions
git diff --name-only
git diff --stat
git diff master..TekTeacher(current branch is optional)
git diff master..TekTeacher --name-only
git log master...TekTeacher (Note: git diff requires triple dot .. and git log requires double dot ... to get the exact behaviour.)
Rewriting Commit Messages/History:-
=================================
--> git commit --amend -m "new message" (rewriting the commit message for latest commit)
--> git rebase -i(interactive) HEAD~2 : for other commits
note: use reword option, while r=editing commit message
--> git ls-files : for latet commit in current branch to list all files
--> git show --name-only <commit id> : specific file to list
--> git commit --amend --no-edit : # Edit hello.py and main.py git add hello.py git commit
# Realize you forgot to add the changes from main.py git add main.py git commit --amend --no-edit
p, pick = use commit
r, reword = use commit, but edit the commit message
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
f, fixup = like "squash", but discard this commit's log message
d, Drop = remove commit
rebase --continue
rebase --abort
rebase --skip
Fetch and pull:-
----------------
pull = fetch + merge
git fetch origin: i.e all the repos in the github will come to local repository,
git merge origin/master : to integrate the commitids
workflow:-
=========
| Add | Commit | |
|------------------------>|---------------------->| |
|----------------Commit -a ---------------------->| git push |
| | |----------------------------->|
Working Dir Index Commiting Area Remote Repository(GitHub)
(work space) (Staging) (HEAD) |
| | |<----------git fetch----------|
|<-------------------Merge------------------------| |
| | | |
|<----------------------------------Pull-----------------------------------------|
|<--------------------diff HEAD------------------>| |
|<----------diff--------->|
Note:- the above commit -a option will only work for already known files to staging area(i.e old files)
reflog:-
========
it shows when we commit,checkout branch, reset....etc
git reflog
git reflog show --all
git reflog show <branch_name>
git reflog master@{1.minute.ago}
git reflog show HEAD@{5}
** Basically "git blame <file_name>" is used to show what revision and author last modified each line of a file.
It's like checking the history of the development of a file.
=========THE END=======
TekTeacher +91- 7204143230(WhatsApp/Call),E:- [email protected]