-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_forget.txt
125 lines (107 loc) · 4.79 KB
/
git_forget.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
# Reference: (git tutorial) https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
# add this repo to local
echo "# git" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/haiboumich/git.git
git push -u origin master
# basic push usage
git status
git add -A
git commit -m "info"
git push
# return to the old commit by X
$ git reset --hard HEAD~X
$ git pull --rebase
# compare remote and local commit
$ git log master..origin/master
$ git log origin/master..master
# update to local
$ git status # make sure there is no conflict before update
$ git checkout -- filename # if the file has changed, we can restore it; if the file needs to be updated to the server, do the merge before update to local
$ git branch # check the branch status
$ git check out [remote branch] # if it is the local branch, then we need to change to the remote branch
$ git pull
# local create a new branch and push to remote
## local create and checkout to a new branch
$ git checkout -b branchName
## push the created branch to remote
$ git push origin branchName:branchName # localBranch:remoteBranch
## build the connection from local to remote which makes it possible to push
$ git push --set-upstream origin mysql_delay_monitor
# show remote and local branch
$ git remote show origin
# sync to rm the remote deleted branch
$ git remote prune origin
# rm redundant local branch
$ git branch -D branchName
# switch the branch
$ git branch -a # check all the branches
$ git branch # check the local branch
$ git checkout [remote branch] # change to the branch
# something might be helpful
$ git checkout -b [new branch] [origin]/[new branch]
$ git checkout master # switch back to master
# update the local list of remote branches
$ git remote update origin --prune
# merge
$ git checkout <destination branch>
$ git merge <source branch>
$ git push
# pit: merge must be based on the local, a.k.a, if you want to merge from dev to master, you must pull the dev to local first.
# revert to a specific commit
$ git reset --hard <hash>
# revert to the current commit, like I want to stop the merge
$ git reset --hard HEAD
# check the diff between HEAD version
$ git diff version_num1 version_num2
# clone the certain branch
$ git clone -b branch .git
# check the user.email
$ git config --global user.email
# set the user.email
$ git config --global user.email "<email>"
# Some other knowledges
$ git add -A # stage all changes
$ git add . # stage new files and modification, without deletions
$ git add -u # stage modification and deletions, without new files
# reset
# after "git add"
$ git reset HEAD # reset all
$ git reset HEAD <filepath> # reset a certain file, remove this file from the buffer
# after "git commit"
$ git reset --soft HEAD^ # revoke the commit but keep the local code, HEAD^ means the last version
$ git reset --mixed HEAD^ # same as the default "git reset HEAD^", in addition to revoking commit like --soft does, it will also revoke "git add"
$ git reset --hard HEAD^ # in addition to what --mixed does, it will also revoke the local code modifications
# after "git push"
$ git revert <commit code> # make sure the local tree is clean, revert the local code to a historical one(use "git log" to check all the commit history)
$ git push
# difference between "git revert" and "git reset"
"git revert" is to use a new commit to revoke a old commit, "git reset" is to delete a certain commit
# add some new file into the same commit
$ git commit -m "initial commit"
$ git add forgotten_file
$ git commit --amend
# common zsh alias
$ gaa # git add -A
$ gcam # git commit -a -m
$ gp # git push
$ gl # git pull
$ gb # git branch
$ gba # git branch a
$ gd # git diff
# roll back remote version
$ git reset --hard <version>
$ git push -f
# roll back cooperation: if u r cooperating with a teammate, and he rolls back to commit1 after push commit1 and commit2 sequentially. Assume u have synced commit1 and commit2, which means u need to sync the roll back action
$ git pull
$ git reset --hard origin/<branch-name> # make sure u have commit the personal local change as it will reset all code to commit1
# When you switch to a branch and something like this shows up, the reason might be that you teammate has rolled back some commits and you are still in the old newest commit
# Your branch is ahead of 'origin/master' by 2 commits.
# (use "git push" to publish your local commits)
$ git reset --hard origin/master # which means forget everything in local branch and keep it exactly same as remote origin/master
# forked repo wants to get the new branch created in original repo after forked
$ git remote add <original-org>/<project-name> <orginal repo addr>
$ git fetch <original-org>/<project-name>
$ git checkout <new branch in original org>