-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathGIT.txt
More file actions
1467 lines (1114 loc) · 31.5 KB
/
GIT.txt
File metadata and controls
1467 lines (1114 loc) · 31.5 KB
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
######################
Day 7 : 16th Apr. 2025
######################
Version Control System using GIT & GitHub ::::
Developer :
index.html
payment.java
IDE -
index.html
-----
---
-
-
-
-
-
-
---
-----
save the file as index.html
Testing
Open index.html
-----
---
-4545
3434534
-345345345
-34534
-345345345
-
-asdfsd
---
-----
save the file as index.html
Testing
Open index.html
-----
---
-4545
3434534
-345345345hhh
-34534hhhh
-345345345
-hhh
-asdfsd
---
----- hhhhh
save the file as index.html
Testing
Version Control System :
- Is used to version control the source code Changes
- Is used to track the source code changes
Using Version Control System like GIT :
index.html
-----
---
-
-
-
-
-
-
---
-----
save the file as index.html ==> index.html_v1.0
-----
---
-4545
3434534
-345345345
-34534
-345345345
-
-asdfsd
---
-----
save the file as index.html ==> index.html_v1.1 --> v1.1 - version_no,tag,commit_id
save the file as index.html ==> index.html_v1.2
save the file as index.html ==> index.html_v1.3
save the file as index.html ==> index.html_v1.4
save the file as index.html ==> index.html_v1.5 --> Latest Version
Types of VCS :
- Local VCS
- Centralized VCS
- Distributed VCS
Distributed Version Control System :
Git :
- Git is one of the open-source distributed version control systems
- It is used to Track the Changes
- Used to Version Control the Source Code Changes
- GIt is used to enable parallel Development using Git Branching
Working with GIT :::
- Install git cli in local machine
- Create GitHub Account
- Install Visual Studion Code.
######################
Day 8 : 17th Apr. 2025
######################
Version Control System using GIT :::
Working with Git :::
Developers' Workload ???
- Enhancement Projects / Bug fixing # Existing Project - Source Code is already available in the Remote Repository
- New Project
Repository ==> Collection of Files and Folder - version controlled in local/remote environments
Git file Workflow :::
Local Machine Remote Server
Install Git Client (VCS) (GitHub)
Working Directory Staging Area Local Repository Remote Repository
index.html ---------------> index.html ---------------> index.html_v1.0 ---------------> index.html_v1.0
git add git commit git push
index.html ---------------> index.html ---------------> index.html_v1.1 ---------------> index.html_v1.1
git add git commit git push
index.html ---------------> index.html ---------------> index.html_v1.2 ---------------> index.html_v1.2
git add git commit git push
index.html ---------------> index.html ---------------> index.html_v1.3 ---------------> index.html_v1.3
git add git commit git push
index.html ---------------> index.html ---------------> index.html_v1.4 ---------------> index.html_v1.4
git add git commit git push
git cli commands :::
git clone # To copy/clone the entire remote repository to local machine
git add # To add the changes from Working Directory to Staging Area
git commit # To Commit the Changes from Staging Area to Local Repository
git push # To push the changes from Local Repository to Remote Repository
git fetch/git pull #
- Both git fetch and git pull are used to handle the incremental changes from remote repository
- git fetch :
git fetch is used to just check for the incremental changes. If there is any incremental changes present in the remote repository, the information about the incremental changes will be updated only in the Local Repository. The Actual File Changes will NOT be updated in the Working Directory. Later the changes can be explicitly merged to Working Directory using Branches. using git merge/git pull
- git pull :
git pull is used to check for the incremental changes. If there is any incremental changes present in the remote repository, the information about the incremental changes will be updated in the Local Repository as well as in the Working Directory.
git pull = git fetch + git merge
Fork # To Copy one Remote Repository to Another Remote Repository
git init # To initialize a local git repository
# Creates .git Directory
# Creates a default branch called - main/master
Working with Local Git Client ::::
1. Install git client in Local Windows Machine ? ::::
64-bit Git for Windows Setup # https://git-scm.com/downloads/win
- git bash # meant for Linux Users
- git CMD # meant for Windows Users
- git GUI
Windows User - Open Git Bash !
git --version
Mac / Linux Users :
Open the terminal > git --version
Repository Structure ::::
Project Folder/Workspace :
- Java_Web_App_Project1 # Root Directory
- SRC
- Test
- prop
Open git bash :
cd d:
mkdir SA-DevOps-AI
cd SA-DevOps-AI
mkdir repo1
cd repo1
git init
######################
Day 9 : 21st Apr. 2025
######################
Working with Git CLI Commands :
git init
git status # get the current status of git repository
Local Machine Remote Server
Install Git Client (VCS) (GitHub)
Working Directory Staging Area Local Repository Remote Repository
file1.txt ---------------> file1.txt ---------------> file1.txt ---------------> index.html_v1.0
git add git commit git push
git init
git status
echo "rec1" >> file1.txt
git add file1.txt
git commit -m "Created file1.txt"
git log # Is used to get the list of commits in current branch
Git Config :
Local Configuration: # within a specific repository
git config user.name "Loksai"
git config user.email "[email protected]"
Global Configuration # Applicable to all the Repositories.
git config --global user.name "Loksai"
git config --global user.email "[email protected]"
For the Very first commit :
git init
git config --global user.name "Loksai"
git config --global user.email "[email protected]"
git status
echo "rec1" >> file1.txt
git add file1.txt
git commit -m "Created file1.txt"
git log # Is used to get the list of commits in current branch
ls # Linux Command to get the list of files/Dirs
git ls-files # get the list of files that being tracked by git from staging / local repository
GIT Add Command ::::
git add <file_name>
git add <file1_name> <file2_name>
git add *.java *.html
git add . # Add all untraced changes/files to staging area
Un-Stage:::: # Undo the changes from Staging area.
# From Staging area, the Changes will be back to working directory.
git rm --cached s1.txt # It will just remove the changes from staging and take the changes back to working directory
git rm -f s2.txt # It will remove the file permanently from staging area as well as from the working directory
Git Log ::::
git log # Is used to get the list of commits in current branch
git log --oneline # Get the list of commit with short commit id and message
git log --oneline -3 # To get the last 3 Commits
git log -3
git log --stat -1
git show <commit_id> # Get the details of the commit at the record level
git diff # Get the difference between the new changes and the committed changes
Undo the Committed Changes :::
- git reset :::
git reset is used to undo the changes from the repository
git reset will reset the commit point to the previous commit point
git reset will not create any new commit point for track purpose
git reset is not recommended in the shared repository
Syntax :
- git reset <reset_option> <previous_Commit_ID>
Reset Options ::
git reset --soft <previous_Commit_ID> :::
- git reset will reset the HEAD pointer to the previous commit point.
- It will take the changes back to staging area
- The Changes will be available in staging area and working directory
git reset --mixed <previous_Commit_ID> ::: # Default
- git reset will reset the HEAD pointer to the previous commit point.
- It will take the changes back to working directory
- The Changes will be available only in working directory
git reset --hard <previous_Commit_ID> :::
- git reset will reset the HEAD pointer to the previous commit point.
- It will permanently delete the files from the system
Commit Points :
5 # Latest Commit
4
3
2
1
git reset --hard 3
3
2
1
501 cd d:
502 cd SA-DevOps-AI
503 ls
504 cd SA-clear
505 clear
506 pwd
507 ls
508 cd SA-DevOps-AI-17/
509 clear
510 ls
511 cd sample-repo
512 cd sample-repo1/
513 cd ..
514 cd sample-repo2/
515 clear
516 cd ..
517 cd sample-repo1/
518 ls
519 ls -a
520 cd ..
521 ls
522 rm -rf sample-repo*
523 ls
524 mkdir repo1
525 clear
526 cd repo1/
527 clear
528 pwd
529 git init
530 ls -a
531 cd .git/
532 ls
533 cd ..
534 clear
535 ls
536 ls
537 git status
538 ls
539 echo "rec1" >> file1.txt
540 ls
541 git status
542 git add file1.txt
543 git status
544 git commit -m "Created file1.txt"
545 git log
546 ls
547 echo "rec1" >> file2.txt
548 ls
549 git status
550 git add file2.txt
551 git commit -m "Created file2.txt"
552 git status
553 git log
554 cd d:
555 cd SA-DevOps-AI-17/
556 ls
557 mkdir repo2
558 clear
559 cd repo2/
560 clear
561 pwd
562 git init
563 git status
564 ls
565 clear
566 echo "rec1" >> f1.txt
567 ls
568 git status
569 git add f1.txt
570 git status
571 git commit -m "Created f1.txt"
572 git status
573 git log
574 echo "rec1" >> f2.txt
575 git add f2.txt
576 git commit -m "Created f2.txt"
577 git log
578 clear
579 git log
580 git config --global user.name "Loksai"
581 ls
582 echo "rec1" >> f3.txt
583 git add f3.txt
584 git commit -m "Created f3.txt"
585 git log
586 cd ..
587 ls
588 cd repo1/
589 git log
590 echo "rec1" >> file3.txt
591 git add file3.txt
592 git commit -m "Created file3.txt"
593 git log
594 clear
595 cd ..
596 mkdir repo3
597 cd repo3/
598 clear
599 git status
600 git init
601 git status
602 clear
603 ls
604 git status
605 git log
606 clear
607 echo "rec1" >> s1.txt
608 git status
609 clear
610 git status
611 git add s1.txt
612 git status
613 clear
614 ls
615 git ls-files
616 git status
617 git commit -m "Created s1.txt"
618 git status
619 git log
620 git ls-files
621 ls
622 echo "rec1" >> s2.txt
623 ls
624 git ls-files
625 git status
626 git add s2.txt
627 ls
628 git ls-files
629 clear
630 git status
631 git commit -m "Created s2.txt"
632 clear
633 ls
634 git status
635 clear
636 ls
637 echo "s3.txt"
638 ls
639 echo "rec1" >> s3.txt
640 clear
641 git status
642 ls
643 echo "rec1" >> s4.txt
644 echo "rec1" >> s5.txt
645 echo "rec1" >> s6.txt
646 git status
647 echo "rec1" >> a1.java
648 echo "rec1" >> a2.java
649 echo "rec1" >> a3.java
650 echo "rec1" >> a4.java
651 echo "rec1" >> q1.doc
652 echo "rec1" >> q2.doc
653 echo "rec1" >> q3.doc
654 echo "rec1" >> l1.html
655 echo "rec1" >> l2.html
656 echo "rec1" >> l3.html
657 git status
658 git add a1.java l1.html
659 git status
660 git add *.java *.html
661 git status
662 git add .
663 git status
664 git ls-files
665 git commit -m "Created somefiles"
666 clear
667 echo "rec1" >> k1.txt
668 git add .
669 git status
670 echo "rec1" >> t1.txt
671 git add .
672 git status
673 git rm --cached k1.txt
674 git ls-files
675 git status
676 git add .
677 git status
678 git rm -f k1.txt
679 ls
680 git status
681 git rm -f t1.txt
682 git status
683 clear
684 git log
685 echo "rec1" >> i1.txt
686 git add .
687 git commit -m "Created i1.txt"
688 echo "rec1" >> i2.tx
689 git add .
690 git commit -m "Created i2.txt"
691 echo "rec1" >> i3.txt
692 git add .
693 git commit -m "Created i3.txt"
694 echo "rec1" >> i4.txt
695 git add .
696 git commit -m "Created i4.txt"
697 clear
698 ls
699 clear
700 git status
701 clear
702 git log
703 clear
704 git log
705 git log --oneline
706 git log --oneline -3
707 git log --oneline -2
708 git log --oneline -1
709 git log --oneline
710 git log --oneline -5
711 git log -2
712 clear
713 git log --stat -1
714 git log -1
715 git log --oneline -1
716 git show f164927
717 clear
718 git status
719 ls
720 clear
721 cat a1.java
722 echo "rec2" >> a1.java
723 cat a1.java
724 git status
725 git diff
726 clear
727 ls
728 cd ..
729 mkdir repo4
730 clear
731 ls
732 cd repo4/
733 clear
734 git init
735 echo "rec1" >> q1.txt
736 git add .
737 git commit -m "CM1"
738 echo "rec1" >> q2.txt
739 git add .
740 git commit -m "CM2"
741 echo "rec1" >> q3.txt
742 git add .
743 git commit -m "CM3"
744 echo "rec1" >> q4.txt
745 git add .
746 git commit -m "CM4"
747 echo "rec1" >> q5.txt
748 git add .
749 git commit -m "CM5"
750 clear
751 git log --onelines
752 git log --oneline
753 ls
754 git ls-files
755 git status
756 git log --oneline
757 git reset --soft 4e1b027
758 git status
759 ls
760 git ls-files
761 git log --oneline
762 git commit -m "CM5.1"
763 ls
764 git ls-files
765 git status
766 git log --oneline
767 git reset --mixed 4e1b027
768 git status
769 ls
770 git ls-files
771 git log --oneline
772 git add .
773 git commit -m "CM5.2"
774 ls
775 git ls-files
776 git status
777 git log --oneline
778 git reset --hard 4e1b027
779 ls
780 git ls-files
781 git status
782 git log --oneline
783 git reset --hard 4b173c6
784 git log --oneline
785 ls
786 git ls-files
787 git status
788 git reset --hard 782846b
789 git status
790 git ls-files
791 ls
792 git log --oneline
793 clear
794 git log --oneline
795 ls
796 cd ..
797 history
Next :::
- git revert :::
#######################
Day 10 : 22nd Apr. 2025
#######################
GIT Revert ::
- Git Revert is same as git reset --hard option
- git revert is used to undo a specific commit
- git revert will create a new commit point for tracking purpose.
- git revert will maintain the commit history
- git revert is recommended in shared repositories
Syntax ::
git revert <specific_Commit_ID>
Eg.:
git revert 018f99a
Create a Commit Point using a commit message
GIT IGNORE :::
- Used to Ignore the files from tracking
- If you don't want git to track any file. using git ignore!
.gitignore --> save the file names to be ignored.
- As a best practise, .gitignore should be the very initial commit.
vi .gitignore
$ cat .gitignore
sample.txt
app.war
target/
s1.doc
*.md
git add .
git commit -m "Initial Commit"
Java_Web_App_Project
SRC
main.java
test.java
app.properties
target
mywebapp.war
DB_Secret
DB_USer_Name
DB_Password
GIT Branch :::
GIT Branching Strategies :
Create GIT Branches :::
Working with git branches enabling parallel development :
GIT Branching Techniques ::::
In Distributed VCS, Branches are used to perform parallel Development
Default Branch - master/main - is considered as a production version of source code.
GIT Branching Strategies :::
- It is used to maintain the integrity of master/main branch
- Git Branch is the logical copy of the default branch
Repo1 :
master - rel1,rel2,rel3
rel1,rel2,rel3,rel4 # rel4 is - feature_branch1 changes upon merge
feature_branch1 - rel1,rel2,rel3,f1cm1,f1cm2,f1cm3
Scenario 1 :
Repo1 :
master - cm1,cm2,cm3
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3,f2cm1,f2cm2,f2cm3 ==> Upon Merging feature1 & feature2
feature1 - cm1,cm2,cm3
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3
feature2 - cm1,cm2,cm3
- cm1,cm2,cm3,f2cm1,f2cm2,f2cm3
Create Branch
git branch # Used get the list of branches
git branch <new_branch_name> # Create New Branch
git switch -c <new_branch_name> # Create New Branch
git switch <branch_name> # Switch to any existing branch
git merge # Used to Merge the Changes to Target Branch
# Should be executed from the target branch
git merge feature1 # Should be executed from the target branch
How Merge Conflict Occurs ::
- When more than one user/feature try to update a same line in the same file on the same target branch, merge Conflict Occurs.
How to fix the Merge Conflict ::
1. Identify the file(s) causing the Merge Conflict
2. Open and review the file content
3. Upon review, decide which record should be retained or deleted from that file
4. Open the File in edit mode, and delete the header and footer lines, and update the file with required records and save it.
5. perform git add and commit to the target branch
Next :
GIT REBASE :
GIT SQUASH :
GIT STASH :
Handling Remote GIT Repositories :
Accessing GITHub Repositories using Visual Studio Code :
- Install Visual Studio Code
- Github Account Account
#######################
Day 11 : 23rd Apr. 2025
#######################
GIT REBASE :
- git rebase :::
- Rebase is used to maintain linear commit history
- Rebase is used to keep the current branch in-sync with target branch
- Rebase can prevent merge-conflicts in the target branch
- As a best practise, it is always recommended to use rebase before merge
Repo1:
master - cm1,cm2,cm3
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3 # Upon merging feature1
- cm1,cm2,cm3,f2cm1,f2cm2,f2cm3,f1cm1,f1cm2,f1cm3 # Upon merging feature2 without proper rebase.
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3,f2cm1,f2cm2,f2cm3 # Expected commits - with proper rebase.
feature1 - cm1,cm2,cm3
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3
git switch master
git merge feature1 ==>
feature2 - cm1,cm2,cm3
- cm1,cm2,cm3,f2cm1,f2cm2,f2cm3
git rebase master # Should be executed from the current branch
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3,f2cm1,f2cm2,f2cm3
git switch master
git merge feature2 ==>
GIT SQUASH :
- It is used to combine the commits into a single commit point.
Repo1:
master - cm1,cm2,cm3
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3,.............................................,f1cm150 # Upon merging without --squash option
feature1 - cm1,cm2,cm3
- cm1,cm2,cm3,f1cm1,f1cm2,f1cm3,.............................................,f1cm150
git switch master
//git merge feature1 ==>
git merge --squash feature1
git commit -m "committed from feature1"
GIT STASH :
- It is used to save the uncommitted changes to the temporary area.
git stash save "msg" # Create an entry in the stash list
git stash list # Get the list of item from the stash list
git stash apply # Apply/Copy the Latest entry from stash list back to staging area
git stash apply stash@{2} # Apply/Copy a specific entry from stash list back to staging area
git stash pop # move the Latest entry from stash list back to staging area
git stash pop stash@{2} # move a specific entry from stash list back to staging area
git stash drop # Delete the Latest entry from stash list
git stash drop stash@{2} # Delete a specific entry from stash list
git stash clear # Clean-up / Delete all the entries from stash list
800 mkdir testrepo1
801 cd testrepo1/
802 git init
803 clear
804 git status
805 echo "rec1" >> q1.txt
806 git add .
807 git commit -m "CM1"
808 echo "rec1" >> q2.txt
809 git add .
810 git commit -m "CM2"
811 echo "rec1" >> q3.txt
812 git add .
813 git commit -m "CM3"
814 echo "rec1" >> q4.txt
815 git add .
816 git commit -m "CM4"
817 clear
818 git log --oneline
819 clear
820 git status
821 ls
822 git ls-files
823 git log --oneline
824 git show 018f99a
825 git revert 018f99a
826 ls
827 git ls-files
828 git status
829 git log
830 git log --oneline
831 git ls-files
832 git revert 279f689
833 ls
834 git ls-files
835 git lg --oneline
836 git log --oneline
837 ls
838 git show 917b6ae
839 git revert 917b6ae