分支
創(chuàng)建并切換至新分支 dev
git checkout -b dev
查看分支
git branch
push an existing repository from the command line
git remote add origin https://github.com/mozjiang/jekyll-demo.git
git push -u origin master
對特定文件不追蹤
在 .gitignore 中寫入
/images
對名字為'images'的文件和文件夾都不追蹤。
/images/
僅對名字為'images'的文件夾不追蹤
git 對已追蹤的文件取消追蹤
你需要 git rm --cached <file>
命令
如:
git rm -r --cached WebRoot/WEB-INF/classes/**/*
代理相關(guān)
設(shè)置 socks 5 代理
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
git push 或者 clone 出錯
出錯代碼:
error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
ffatal: The remote end hung up unexpectedly
atal: early EOF
fatal: index-pack failed
解決方法:增大 postbuffer
git config --global http.postBuffer 1048576000
git 初始化相關(guān)操作
你在安裝 Git 之后想要做的第一件事是告訴它你的名字和郵箱瀑凝,個性化一些默認設(shè)置。一般初始的設(shè)置過程看上去是這樣的:
# 告訴Git你是誰
git config --global user.name "zhang san"
git config --global user.email john@example.com
# 選擇你喜歡的文本編輯器
git config --global core.editor vim
# 添加一些快捷方式(別名)
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.up rebase
git config --global alias.ci commit
git commit
git add hello.py
git commit
它會打開一個文件編輯器(可以通過 git config 設(shè)置) 詢問提交信息吞彤,同時列出將被提交的文件。
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
#modified: hello.py
Git 對提交信息沒有特定的格式限制叹放,但約定俗成的格式是:在第一行用 50 個以內(nèi)的字符總結(jié)這個提交饰恕,留一空行,然后詳細闡述具體的更改井仰。比如:
Change the message displayed by hello.py
- Update the sayHello() function to output the user's name
- Change the sayGoodbye() function to a friendlier message
注意埋嵌,很多開發(fā)者傾向于在提交信息中使用一般現(xiàn)在時態(tài)。這樣看起來更像是對倉庫進行的操作糕档,讓很多改寫歷史的操作更加符合直覺莉恼。
git log
用法 一節(jié)提供了 git log 很多的栗子,但請記住速那,你可以將很多選項用在同一個命令中:
git log --author="John Smith" -p hello.py
這個命令會顯示 John Smith 作者對 hello.py 文件所做的所有更改的差異比較(diff)俐银。
..句法是比較分支很有用的工具。下面的栗子顯示了在 some-feature 分支而不在 master 分支的所有提交的概覽端仰。
git log --oneline master..some-feature
You can undo git add before commit with
git reset <file>
which will remove it from the current index (the "about to be committed" list) without changing anything else.
You can use
git reset
without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.
git push -u origin master