-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGIT.txt
246 lines (143 loc) · 7.1 KB
/
GIT.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
git config --global user.name 'abc' #nesessary for identify changes in repo
git config --global user.email '[email protected]'
# if we need to define username and email locally, only in some repo:
git config user.name "Your Username"
git config user.email "[email protected]"
git config --local --list #check the local configuration
git config -l #check the congiguration on linux
type .\.gitconfig # check config on windows
dir # check the dir in windows
git init \Users\under\myproject\ #create local database for repository
git status #check the status of the repo
git add * #add all files in dir to commit
#add files to staging status
git commit -m "my initial commit, version1.0"
#Takes the staged snapshot and commits it to the project history.
git log #check history of git changes in logs
git log -2 # show last 2 logs
git log -2 -p #+add details about log
git checkout -- file1.txt #discard changes in file1
git diff --staged #show what will be write in commit
#diff between now and last commit
git diff master #show the difference between current branch and the master branch
git diff 1fa95770f4ea1d640fcf7e4d06a25e99c10d6bed 26282f9fdd8cecb2f105abf6a04db689e98b815b
#difference between 2 commits
git diff 1fa95770f4 26282f9fdd8 #the same, short version of commit's tags
#it works if at the begin we have unque numbers
New-Item .gitignore #create new file .gitignore
git remote add origin 'your_url_name' #add remote repository before pushing
git remote rm origin #delete way to the remote repo
git push origin #push existing project to github repo
ssh-keygen #generate keys on linux server in console
git remote -v #connect with github
git clone [email protected]:Andr1500/organization.git
#clone the repo from github
ssh-keygen (in git-bash) #generate keys on windows
git branch #show branches in main repository
git branch fix_error # create new branch "fix_error"
git switch remote_fix_error #switch to the branch which was added to the remote repo
git checkout fix_error #switch on another branch
git branch -d fix_error #delete branch "fix_error"
git checkout -b fix_error1 #create new branch and switch on it
git merge fix_error1 #merge (connect) another branch with master branch
###########################
merge from "feature" branch into "main" branch:
switch to "main" branch and merge "feature" branch into it:
git merge --squash featurer_branch
git commit -am "merged changes from feature branch"
###########################
git checkout 25b8c45cd8051cbd8a8676ac1c7f07374222b48f
#switch on another (previosly) version
git commit --amend # amend (change) info in commit
git commit -a -m "..." #add and commit changes in tehe repository
git reset --hard e4f61ba #delete all changes and come back to the commit
git reset --soft e4f61ba #make the commit as first (just in logs), all the changes will store
git revert HEAD #revert changes 1 commit back
in case, if we need to revert multiple Git commits:
A <-- B <-- C <-- D <-- [(BCD)-1] <-- master <-- HEAD
$ git revert --no-commit D
$ git revert --no-commit C
$ git revert --no-commit B
$ git commit -m "the commit message for all of them"
git push --set-upstream origin a1500_change_CH259874
#push into github repo from another branch
GitHub -> Insights -> Network #here we can see branches and history
Project -> Commits -> "Choose commit" -> Browse files
#see the changes related to some commit
push origin --delete a1500_change_CH259874
#delete remotely (from github) the branch
work with someone else's repository:
fork it to own GutHub account, clone it locally, work with it, push on GitHub, merge (if necessary) to original repo
git rebase master #Reapply commits on top of another base tip(when you are in another branch),
it's like copying commits from another branch to the current branch
git remote remove origin
#delete remote repo which set up locally
#####################
Delete all commits history but keep the code in its current state:
Checkout:
git checkout --orphan latest_branch
Add all the files:
git add -A
Commit the changes:
git commit -am "commit message"
Delete the branch:
git branch -D main
Rename the current branch to main:
git branch -m main
Finally, force update your repository:
git push -f origin main
########################
delete all git configuration and next inti git repo and push to remote:
rm -fr .git
git init --initial-branch=main
git remote add origin [email protected]:GitAccount/gitRepo.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin main
##########################
remove the old history from a git repository:
git checkout --orphan temp $1 # create a new branch without parent history
git commit -m "Truncated history" # create a first commit on this branch
git rebase --onto temp $1 master # now rebase the part of master branch that we want to keep onto this branch
git branch -D temp # delete the temp branch
($1) is a reference (tag, hash, ...) to the commit starting from which you want to keep your history
#########################
make git cherry-pick. Cherry pick applies the changes introduced by the cherry picked commit onto the current branch.
If changes introduced by the picked commit conflict with changes to those files on the current branch, you will see a merge conflict.
How to fix a Git Cherry Pick merge conflict
Get the unique identifier of the commit you want to pick
git log <branch-name> --oneline
Use cherry-pick to grab that commit by specifying it’s identifier
git cherry-pick <commit-hash>
When cherry-pick fails with a merge conflict note the file(s) that failed the merge. Open each of the failed files in a text editor of your choice and manually resolve the conflicts. After saving the files, stage them:
git add <file(s)-that-failed-merge>
Continue the cherry-pick operation
git cherry-pick --continue
also, we can do that with some merge tools:
Install a proper mergetool. On Linux, I strongly suggest you to use meld:
sudo apt-get install meld
Configure your mergetool:
git config --global merge.tool meld
Then, iterate in the following way:
git cherry-pick ....
git mergetool
git cherry-pick --continue
##########################
save not staged changes, make rebase with other branch and continue work with the saved changes
1. stash changes :
git stash push -m "Description of your work in progress"
2. rebase changes :
git rebase origin/staging
3. apply stashed changes :
git stash pop
############################
add changes from other branch, commit it
git checkout branch-with-changes -- file_name.txt
git reset HEAD file_name.txt # unstage the file
git diff file_name.txt # see diff for comment
git add file_name.txt
git commit -m 'change file_name.txt'
###########################
in case of any rebase, it's necessary to push with -force option,
safety it can be done with this command:
git push --force-with-lease