-
Notifications
You must be signed in to change notification settings - Fork 0
/
readMe.txt
86 lines (62 loc) · 3.22 KB
/
readMe.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
Github
1) For reverting back tha last commit into local
git reset HEAD~1
2) For completely reverting local commit without even looking at the changes for example. (This will delete upper commits)
git reset --hard HEAD~1
and then commit and push
https://stackoverflow.com/questions/927358/how-do-i-undo-the-most-recent-local-commits-in-git/34547846
3) Git has one remote and one local brannch.When you checkout it gives you the local branch for example in case of git checkout master , it will be local data only with +- comits ahead .For sync you need to do git pull
4) How to merge previous commits into single commit : use interactive rebase and squash or fixup
5)How to change message of previous commits.Use ineractive rebase and use reword.
6)Change previous commit : use git rebase and then use edit to the commit which you want to do and then use rebase --continue
6)Change previous commit:
git commit --amend -m "abccc"
you can add more file and all the staged filed will adup in previous commit with new message.
7) Scenario : Reverting last merge / last comit in the branch like when production system fails.
Command : git revert HEAD , then git push
This wont override anything but will create a new commit over latest commit nullfyling its affect.
6)When remote branch is ahead of curent branch.
git pull
(resolve conflicts)
git merge --continue
repeat
git push
8) Resolving merge conflict using merge
checkout feature branch
git pull origin master
resolve conflicts and add file to staging
git merge --continue
Repeat
git push
9)Resolving merge conflict using rebase
go to feature branch
git rebase master
resolve conflict
git rebase --continue
repeat
git push
10)When to use merge and when rebase? basically rebase is great option if you want to maintain a clean history and do not want unnecessary merge commits but should not be applied to a public branch.
11)Remove file after it has been pushed.
12) interactive rebase
git rebase -i HEAD~3
13) interactive rebase
git rebase -i HEAD~3
14) cherry pick : Picking up commit from some other branch and applying changes on current branch.
git cherry-pick commitHash or git cherry-pick --no-commit commitHash
( In the former commit will be made and in later it would be added in staging)
https://www.atlassian.com/git/tutorials/cherry-pick
15) git bisect will help youin finding bug using binary search .
git bisect start
git bisect good commithash
git bisect bad commithash
git bisect good
git bisect bad
15)Git show will tell you exact author details, commit message and what changes to which file were done.
example git show commithash
16)git reset hard soft mixed
https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard
When using git reset --soft HEAD~1 you will remove the last commit from the current branch, but the file changes will stay in your working tree. Also the changes will stay on your index, so following with a git commit will create a commit with the exact same changes as the commit you "removed" before.
17) revert 4-5 commits
git reset --hard 5d7629b5b84af376403a0760c9c000b1c0aaf
git push -f
or git revert multiple times starting from last (Always avoid push -f wherever possible)