-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_command.txt
191 lines (152 loc) · 8.01 KB
/
git_command.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
git init
echo "xxx">ReadMe.txt
git status
git add ReadMe.txt
git commit -m "xxxx"
git commit --amend
git log
git add -u
git diff dd68lq....a12ec6
git diff HEAD~1...HEAD
git diff HEAD~1...
git add -A
git checkout => pull out from the repository by default grab the head version
git checkout 54560a3
cat filename
git stash
git stash list
git stash pop
git stash apply (apply the saved stash without remove it)
git checkout feature/csvgenerator /**/
git pull -r origin master
git conifg --global user.name "Sam Smith" (--global flag tells Git to use this configuration as a default for all of your repositories)
git config --global user.email sam@example.com
git add *
git remote add origin <server>
git remote -v
git clone /path/to/repository
git clone username@host:/path/to/repository
git clone https://github.com/jquery/jquery.git
git log --oneline --graph --all --decorate
git log --oneline
git log --oneline | wc -l (word count function with the -l to count line by line)
git log --oneline --graph
git log --format=short
git log --oneline blue.html (this display only the blue.html history)
git log oldbranch ^newbranch --no-merges (show commit in oldbranch but not in newbranch) //https://stackoverflow.com/questions/1710894/using-git-show-all-commits-that-are-in-one-branch-but-not-the-others
git shortlog
git shortlog -sne
git show HEAD (last commited)
git show HEAD~1
git show adf2342 (show commited by hash)
git remote (show that we have got one remote called origin, origin is just the git defautl name for where this souce came from)
git remote -v
//local repository that i want to add to remote destnation
git remote add origin https://github.com/fish0185/GitTest.git (origin is random name, you can named it anything)
git remote rm origin (remote origin)
git fetch (pull down from remote repository)
git fetch origin (petch form specific remote)
git log orign/master (here show the remote branch orign/master 's log)
git merge origin/master (specify the merging from origin master int to my current branch called master)
git reset --merge // will abort a merge
git merge --abort // same as above, alias
git fetch; git merge origin/master ==== git pull (will update and merge any remote changes of the current branch you're on.)
git pull -r origin master (grab latest source code from orign's master branch and rebase)
git branch --set-upstream master origin/master
git pull origin master (this case you dont need to setup upstream)
git pull --rebase origin master (fetch orgin and rebase your current branch onto the top http://gitolite.com/git-pull--rebase)
git rebase origin/master (get remote source and apply to current branch)
git rebase --abort (revert rebase)
git rebase --continue
//view branches and tags
git branch (display all branches - local)
git branch -r (remote branches)
git checkout -b ZIPDEV-1586 (create a local branch also do a switch to that branch)
git branch -d Zipdev-1598 (delete branch)
git branch -D zipdev-1589 (forece delete branch)
git branch -r -d origin/update/u1 (delete remote branch)
git branch -m new-name // rename your local branch, if you are on the branch you want to rename
git branch -m old-name new-name // rename local branch, if you are on a different branch
git checkout filename (checkout the file from last commited)
git reset --hard HEAD~1 (delete that last commit)
git --soft HEAD~1 (undo last commit - move changes to staging area)
git reset --hard /*remove all changes and take from previous commit*/ (this changes all tracked files to mathc the most recnet commit)
git reset --soft HEAD~1 /*revert last change, still able to change*/
git reset --hard HEAD~1 /*remove last commit*/
git reset <file> // You can undo git add before commit with
git reset //which will remove it from the current index (the "about to be committed" list) without changing anything
git revert 514fbe7 (git revert command requires a commit id to undo) (git revert saves the commit in case you want to come back to it later)
//https://stackoverflow.com/questions/927358/how-to-undo-the-last-commits-in-git?page=3&tab=active#tab-top
// revert change
git revert commit-id
// if conflict just use git mergetool resolve conflict
// git add -A
// git commit -m 'revert change Feature-123'
// Create a pr the origin master
git push --force origin feature/csvgenerator
git rm src/Api/Controllers/filename.cs -f
git remote update (will update all of your branches set to track remote ones, but not merge any changes in.)
git rebase --continue
git mergetool
git tag (these are stable points, these are known points in your code base where you can ofen tag verion)
git tag v1.0 (add tag)
git tag (view tag)
git tag -a V1.1 (create V1.1 with message)
git tag -s v1.2 (try to sign a tag)
git tag -v v1.2 (vertig the tag)
git push --tags (push with tag)
git tag -a v1.0 -m "Stable version of the website" (-a flag tells git to create an annotated tag, which lets us record our name, the date, and a descriptive message(specified via -m flag))
git checkout v1.0 (checout a tag)
git rebase -i HEAD~2 (squash commit)
git remote set-url origin git@bitbucket.org:zipmoney-platform/zipmoney.git(setup or change remote origin)
git push origin feature/csvgenerator
git push origin feature/csvgenerator --force /*not doing this in master*/
git push origin ZIPDEV-1586:feature/zipdev-1586-show-payment-info-for-NZ-payments-service (push local branch[ZIPDEV-1586] to remote + create a remote branch[origin/feature/zipdev-1586-show-payment-info-for-NZ-payments-service])
git push origin feature/csvgenerator (push local branch[which you are in] to remote branch -- origin means remote destination)
# If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
# http://stackoverflow.com/questions/1470572/gitignore-ignore-any-bin-directory
git rm --cached
git rm --cached -r .
git add .
# end of
git fetch (will update only the branch you're on, but not merge any changes in.)
git rebase origin/master (reabase or merge my local branch with these changes)
git pull -r origin master
working direcotry, stagred snapshot, committed snapshots is at the very core of Git Version control
git clean -f (this will remove all untracked files)
// Cherry picking in git means to choose a commit from one branch and apply it onto another
// this is in contrast with other ways such as merge and rebase which normally applies many commits onto a another branch
1. Make suer you are on the branch you want apply the commit to.
git checkout master
2. Execute
git cherry-pick <commit-hash>
git checkout -b test origin/master (create a local copy name test of origin/master)
git checkout -b newBranchName origin/master (checkout remote master to new branch called newBranchName)
# How to make Git “forget” about a file that was tracked but is now in .gitignore?
# https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore
1. git rm -r --cached .
2. git add .
3. git commit -am "Remove ignored files"
// apply stash
1. git stash list // list of stashed
2. git stash apply stash@{x} // x is the stash you want to apply, last one is 0, second last is 1, ect...
// git push with username and passowrd https://stackoverflow.com/questions/29776439/username-and-password-in-command-for-git-push
git push https://username:password@bitbucket.org/xxxx/nodetolambda.git/
// git clone with username password
git clone https://username:passwod@bitbucket.org/xxxx/xxx.git
// find git config localtion
git config --list --show-origin
// how to merge lots commit to new branch
1. checkout the new branch
e.g. git checkout master
2. git merge relase/1.0
3. git mergetool incase conflit
// finish merge
4. git merge --continue or git commit
// git bash keep ask for user crediential #########
git config credential.helper store
git pull
* add your password
// ################################################
//https://stackoverflow.com/questions/12144633/explain-which-gitignore-rule-is-ignoring-my-file
git check-ignore -v filename