1.git 提交出現(xiàn)這個錯誤fatal: Unable to create ‘project_path/.git/index.lock’: File exists. exists
解決辦法
打開git Bash 進(jìn)入項目目錄 ?輸入rm -f ./.git/index.lock ? 再回到AS就可添加了

on Windows
del .git\index.lock
2.使用git 添加遠(yuǎn)程github倉庫的時候提示錯誤:fatal: remote origin already exists.

到解決辦法如下:
1、先刪除遠(yuǎn)程 Git 倉庫
$ git remote rm origin
2、再添加遠(yuǎn)程 Git 倉庫
$ git remote add origin git@github.com:FBing/java-code-generator
如果執(zhí)行 git remote rm origin 報錯的話,我們可以手動修改gitconfig文件的內(nèi)容
$ vi .git/config
把 [remote “origin”] 那一行刪掉就好了。
3. non-fast-forward
$ git push -u origin master
To git@github.com:******/Demo.git
! [rejected]master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
網(wǎng)上搜索了下,是因為遠(yuǎn)程repository和我本地的repository沖突導(dǎo)致的,而我在創(chuàng)建版本庫后,在github的版本庫頁面點擊了創(chuàng)建README.md文件的按鈕創(chuàng)建了說明文檔,但是卻沒有pull到本地。這樣就產(chǎn)生了版本沖突的問題。
有如下幾種解決方法:
1.使用強(qiáng)制push的方法:
$ git push -u origin master -f
這樣會使遠(yuǎn)程修改丟失,一般是不可取的,尤其是多人協(xié)作開發(fā)的時候。
2.push前先將遠(yuǎn)程repository修改pull下來
$git pull origin master
$ git push -u origin master
3.若不想merge遠(yuǎn)程和本地修改,可以先創(chuàng)建新的分支:
$git branch [name]
然后push
$git push -u origin [name]


4,git常用命令
1. git 配置:
git config--globaluser.name"xxx"--配置用戶名,上傳本地 repository 到服務(wù)器上的時候,在 Github 上會顯示這里配置的上傳者信息
git config--globaluser.email"xxx"--配置郵箱
git config--list? ? ? ? 查看配置列表
配置 sshkey : 上傳代碼時使用這個 sshkey 來確認(rèn)是否有上傳權(quán)限
1). 創(chuàng)建本地 ssh :
cd ~/.ssh
ssh-keygen -t rsa -C"Github 的注冊郵箱"2). 在 Github 中添加這個 sshkey :
復(fù)制? /home/bruceking90/.ssh/id_rsa.pub 文件中的內(nèi)容;
登錄 Github--> Account Setting? --> SSH-KEY --> Add SSH-KEY -->粘貼id_rsa.pub中的內(nèi)容;3). 驗證: ssh -T git@github.com
出現(xiàn) Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. 說明配置成功,可以連接上 Github
2. 建立倉庫 repository :
git init here--創(chuàng)建本地倉庫
git remote add origin git@github.com:用戶名/倉庫名.git--把本地倉庫和遠(yuǎn)程倉庫關(guān)聯(lián)起來, 如果不執(zhí)行這個命令的話,每次 push 的時候都需要指定遠(yuǎn)程服務(wù)器的地址
3. 從遠(yuǎn)程倉庫中下載新的改動:
git pull origin master4. 提交本地修改到遠(yuǎn)程倉庫中:
git add
git add-A? ? ? --將改動添加到本地倉庫中
git rm xxx--從本地倉庫中刪除指定文件
git rm-r xxx? --從本地倉庫中刪除指定文件夾
git commit-m"注釋"--把本機(jī)緩存中的內(nèi)容提交到本機(jī)的 HEAD 里面
git push origin master--把本地的 commit push 到遠(yuǎn)程倉庫中
(注釋:如果出現(xiàn)推送錯誤,可以強(qiáng)制性推送git push origin +master或者先git pull,然后再操作庫)
如果有permission deneied,嘗試:?? ssh -i ~/.ssh/id_rsa -vT git@github.com?? ssh-agent?? ssh-add ~/.ssh/id_rsa
Git 常用命令
git init--創(chuàng)建本地倉庫(repository),將會在文件夾下創(chuàng)建一個 .git 文件夾,.git 文件夾里存儲了所有的版本信息、標(biāo)記等內(nèi)容
git remote add origingit@github.com:用戶名/倉庫名.git--把本地倉庫和遠(yuǎn)程倉庫關(guān)聯(lián)起來。如果不執(zhí)行這個命令的話,每次 push 的時候都需要指定遠(yuǎn)程服務(wù)器的地址
git add--從本地倉庫增刪,結(jié)果將會保存到本機(jī)的緩存里面
git rm
git commit-m"注釋"--提交,把本機(jī)緩存中的內(nèi)容提交到本機(jī)的 HEAD 里面
git push origin master-- 把本地的 commit(提交) push 到遠(yuǎn)程服務(wù)器上, origin 也就是之前 git remote add origin 那個命令里面的 origin,origin 替代了服務(wù)器倉庫地址:git pushgit@github.com:用戶名/倉庫名.gitgit pull origin master--從遠(yuǎn)程服務(wù)器 pull 新的改動
git status--查看狀態(tài)
git add-A? ? ? ? ? ? ? --提交全部修改
git clone
使用 git clone 拷貝一個 Git 倉庫到本地,讓自己能夠查看該項目,或者進(jìn)行修改。
如果你需要與他人合作一個項目,或者想要復(fù)制一個項目,看看代碼,你就可以克隆那個項目。 執(zhí)行命令:
git clone [url]
yuleyouxi
yuleyouxi
那說明你有修改過的文件

git提交報錯:Counting objects: 198, done.
Delta?compression?using?up?to?4?threads.
Compressing?objects:?100%?(109/109),?done.
Writing?objects:?100%?(137/137),?405.67?KiB,?done.
Total?137?(delta?74),?reused?0?(delta?0)
remote:?W?refs/heads/intg/dev?scm/p400_system?hongyang.song?DENIED?by?fallthru
remote:?error:?hook?declined?to?update?refs/heads/intg/dev
To?git@10.114.110.37:scm/p400_system.git
!?[remote?rejected]?intg/dev?->?intg/dev?(hook?declined)
!?[rejected]????????master?->?master?(non-fast-forward)
error:?failed?to?push?some?refs?to?'git@10.114.110.37:scm/p400_system.git'
To?prevent?you?from?losing?history,?non-fast-forward?updates?were?rejected
Merge?the?remote?changes?(e.g.?'git?pull')?before?pushing?again.??See?the
'Note?about?fast-forwards'?section?of?'git?push?--help'?for?details.
git?stash
git?pull?--rebase?(每次push之前最好這樣做一次)
git?push?....
之后用git?stash?pop?stash@{0}回復(fù)你之前修改的文件就