forked from RishikeshOps/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit
180 lines (124 loc) · 3.8 KB
/
git
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
Day 3:
*********************
Git reset command and its options
Git reset command:
This command is applied on your commit history. This command is used when you want to discard changes done as part of multiple commits. This command will also delete your commit ids, you will not be able to see the ids
Reset command with its option --hard
can remove changes and commit ids
hence it is also called as a destrcutive command
Once reset command is executed it never generates a commit id or there is no log for its operation
When we use the reset command, we are resetting the HEAD of the commits
git reset --hard <commitid>
Other rest options that are safe to use and used frequently are:
git reset --soft <commitid>
The <commitid> becomes the head and orphan commit id will be deleted fromlog and
files or changes will move back to staging area
git reset --mixed <commitid>
The <commitid> becomes the head and orphan commit ids will be deleted from log and files or changes
will move back to Unstaged area
hard->will delete permanently from WD,staging area,LR
soft->will delete permanently from LR and files will be available in WD and staging area
mixed->will delete permanently from LR and staging area and files will be available in WD
Branching , Merging and rebasing
*********************************************
Branching is a concept in git which allows to you freely work on multiple features at he same time without impacting the main master branch
Whenever we do commits on our repository we have seen a branch named master which gets updated.
Master branch is the default branch which get created upon initializing a repoYou can create any number of branched, a branch is copy of master branch
You can switch to a branch and work/develop on it.Once development or changes are complete on a branch , you can merge it to master branch
You can also rename and delete a branch.
But you cannot delete the master branch.
Scenario 1: Create branches in Local repo
> Command to check how many branches are in Local repo
…
git branch
…
> Create a new branch in our Local repository
…
git branch f1
…
> Switch to a particular branch
…
git checkout f1
…
> Add new file and commit on the branch f1
$ touch feature1
$ git add .
$ git commit -m “added onf1”
$ git log –oneline // check the new commit
> Switch back to master branch and compare the 2 branches
…
git checkout master
…
Assignment
> Compare the 2 branches:
…
git diff --name-status master..f1
…
OR
git diff master..f1
Scenario 2:
> Command to create a new branch as well as switch to new branch
…
git checkout -b f2
…
> Add new file and commit on the new branch
> Switch back to master
Scenario 3: Merge the changes from feature branch to master
> Always switch to the branch where you want to merge the files from feature branch
…
git checkout master
…
> Merge the changes from new branch to master branch
…
git merge <sourcebranch> <destinationbranch>
…
…
git merge f1 master
…
> Check the commit history on master
Scenario 4:
Change the name of the branch
…
git branch -M f1 dev
…
Delete a branch in local:
Make sure , you are not on the branch that is to be deleted
First checkout to master branch
…
git checkout master
…
…
git branch -D f2
…
List of branches that have not been merged to master
git branch --no-merged
List of branches that have been merged to master
git branch --merged
Cherry-pick scenario:
******************************
...
git branch
...
git checkout f2
...
ls
...
touch login
...
git add .
...
git commit -m "f2 login"
...
touch sonal
...
git add .
...
git commit -m "f2 sonal"
...
git log --oneline
...
git checkout master
...
git cherry-pick 66922bf f86a4c9
...
ls