git命令簡介
root@test:/tmp/huhaha# git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
??clone ?? Clone a repository into a new directory
??init ?? Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
??add ?? Add file contents to the index
??mv ?? Move or rename a file, a directory, or a symlink
??restore ?? Restore working tree files
??rm ?? Remove files from the working tree and from the index
??sparse-checkout ?? Initialize and modify the sparse-checkout
examine the history and state (see also: git help revisions)
??bisect ?? Use binary search to find the commit that introduced a bug
??diff ?? Show changes between commits, commit and working tree, etc
??grep ?? Print lines matching a pattern
??log ?? Show commit logs
??show ?? Show various types of objects
??status ?? Show the working tree status
grow, mark and tweak your common history
??branch ?? List, create, or delete branches
??commit ?? Record changes to the repository
??merge ?? Join two or more development histories together
??rebase ?? Reapply commits on top of another base tip
??reset ?? Reset current HEAD to the specified state
??switch ?? Switch branches
??tag ?? Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
??fetch ?? Download objects and refs from another repository
??pull ?? Fetch from and integrate with another repository or a local branch
??push ?? Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
git上傳代碼操作
- 拉代碼到本地倉庫
#克隆一個代碼倉到當(dāng)前環(huán)境刁品,鏈接為你github上鏈接
#會提示你輸入用戶名加密碼,等待結(jié)束即可
root@test:/tmp# git clone http:path.git
Cloning into 'huhaha'...
Username for 'http://xx.xx.xx.xx': user name
Password for 'http://username@xx.xx.xx.xx': password
remote: Enumerating objects: 4066, done.
remote: Counting objects: 100% (4066/4066), done.
remote: Compressing objects: 100% (1673/1673), done.
remote: Total 4066 (delta 2372), reused 4040 (delta 2346)
Receiving objects: 100% (4066/4066), 4.72 MiB | 2.84 MiB/s, done.
Resolving deltas: 100% (2372/2372), done.
- 創(chuàng)建或切換分支
#這里需要注意砰粹,要先切換一下路徑
root@test:/tmp# cd huhaha/
#打印一下當(dāng)前的枝干是主干還是分支
root@test:/tmp/huhaha# git branch
* master
#這里是切換分支操作
root@test:/tmp/huhaha# git checkout huhahah
Branch 'huhahah' set up to track remote branch 'huhahah' from 'origin'.
Switched to a new branch 'huhahah'
#可以看到分支切換過來了
root@test:/tmp/huhaha# git branch
master
* huahahah
- 拷貝代碼到當(dāng)前分支對應(yīng)目錄下劝赔,并將代碼添加到代碼倉
#把我新添加的代碼目錄拷貝到剛剛克隆的代碼倉里
root@test:/tmp/huhaha# cp -r /root/huhaha/scripts/test/ /tmp/huhaha/scripts/
#其他需要拷貝的
root@test:/tmp/huhaha# cd scripts/other
#添加代碼倉操作
root@test:/tmp/huhaha# git add . #注意后面的“.”不能丟
#查看一下狀態(tài),添加成功則會變顏色
root@test:/tmp/huhaha# git status
On branch huhahah
Your branch is up to date with 'origin/huhahah'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
.......done
- commit and push代碼
#在commit之前還需添加一下郵箱及用戶名
root@test:/tmp/huhaha# git config --global user.email "you@example.com"
root@test:/tmp/huhaha# git config --global user.name "Your Name"
#進(jìn)行commit操作谜悟,-m 描述信息
root@test:/tmp/huhaha# git commit -m "add compare case"
[huhahah ed38a60] add compare case
34 files changed, 2006 insertions(+), 12 deletions(-)
......done
#push到github代碼倉
root@test:/tmp/huhaha# git push -u origin huhahah
Username for 'http://xx.xx.xx.xx': user name
Password for 'http://username@xxx.xx.xx.xx': password
Enumerating objects: 51, done.
Counting objects: 100% (51/51), done.
Delta compression using up to 24 threads
Compressing objects: 100% (44/44), done.
Writing objects: 100% (44/44), 12.30 KiB | 4.10 MiB/s, done.
Total 44 (delta 35), reused 0 (delta 0)
remote:
remote: To create a merge request for nvme_read_write, visit:
remote: http://xx.xx.xx.xx/tester/huhaha/merge_requests/new?merge_request%5Bsource_branch%5D=huhahah
remote:
To http://xx.xx.xx.xx/tester/huhaha.git
81424e3..ed38a60 huhahah -> huhahah
Branch 'huhahah' set up to track remote branch 'huhahah' from 'origin'.