git remote -v #獲取遠程倉庫網址信息
git remote add test git@github.com:nodejsnewbie/fzdh.git
remove a remote repository
git remote rm origin
or create a new repository on the command line
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:nodejsnewbie/test.gitgit push -u origin master
or push an existing repository from the command line
git remote add origin git@github.com:nodejsnewbie/test.git
git push -u origin master
Command line instructions
Git global setup
git config --global user.name "fengze"
git config --global user.email "1206215@qq.com"
Create a new repository
git clone https://gitlab.com/fengzejituan/fzdhwebsite.git
cd fzdhwebsite
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/fengzejituan/fzdhwebsite.git
git add .
git commit
git push -u origin master
Existing Git repository
cd existing_repo
git remote add origin https://gitlab.com/fengzejituan/fzdhwebsite.git
git push -u origin --all
git push -u origin --tags
repo目錄下的.git/config咙边,果然,我的url是HTTPS形式。
[remote "origin"] fetch = + refs/heads/:refs/remotes/origin/ url = https://username@github.com/username/projectname.git**
因為遠程版本庫的url是HTTPS敬察,估計是我git clone的時候用HTTPS鏈接造成的
所以問題就出在這了特铝,每次都很不方便炫七,都要輸入用戶名和密碼演熟。
為了使用SSH公鑰的方式認證频敛,我把config的url改成下面這樣
[remote "origin"] fetch = + refs/heads/:refs/remotes/origin/ url = git@github.com:username/projectname.git**
這樣我git push的時候又可以用SSH公鑰認證而不用去輸入用戶名和密碼帮哈,不僅方便膛檀,而且更安全。
允許推送無關歷史代碼
--allow-unrelated-histories
.gitignore只能忽略那些原來沒有被 track 的文件娘侍,如果某些文件已經被納入了版本管理中咖刃,則修改 .gitignore 是無效的。
解決方法是先把本地緩存刪除憾筏,然后再提交嚎杨。
git rm -r --cached .
git add .
git commit -m 'We really don't want Git to track this anymore!'
.gitignore 的匹配規(guī)則:
.a # 忽略所有 .a 結尾的文件
!lib.a # 但 lib.a 除外
/TODO # 僅僅忽略項目根目錄下的 TODO 文件,不包括 subdir/TODO
build/ # 忽略 build/ 目錄下的所有文件
doc/.txt # 會忽略 doc/notes.txt 但不包括 doc/server/arch.txt
查看某個文件的歷史修改
git blame golfMaster/Menu/GMWebViewController.m
git log --pretty=oneline golfMaster/Menu/GMWebViewController.m #會查看所有關于此文件的commit
git show #看某次commit的更改氧腰。
讓單個文件回退到指定的版本
git log MainActivity.java git reset a4e215234aa4927c85693dca7b68e9976948a35e MainActivity.java
git commit -m "revert old file " git checkout MainActivity.java #更新到工作目錄
解決gitignore不生效的問題
git rm -r --cached .
git add .
git commit -m "update"