1、操做git-bashlinux
一、添加 git add 11.txt 22.txt 33.txtgit
二、提交 git commit -m "add wenjian"web
三、git push 提交到遠程服務器(第一次push:git push origin master)bash
四、若是版本號對應不上又提交不了(error: Your local changes to the following files would be overwritten by merge: )服務器
方法1:若是你想保留剛纔本地修改的代碼,並把git服務器上的代碼pull到本地(本地剛纔修改的代碼將會被暫時封存起來)ssh
git stash
git pull origin master
git stash pop
方法二、若是你想徹底地覆蓋本地的代碼,只保留服務器端代碼,則直接回退到上一個版本,再進行pull:post
git fetch --all
git reset --hard origin/master
五、企業協同時fetch
1)、 git checkout lzh //切換到本身分支;spa
2)、 git merge --no-ff develop //把develop的修改merge到 lzhcode
3)、再git push origin lzh //在本身分支上提交,看是否有衝突,並處理衝突
4)、git push origin develop //正式提交到develop
六、git pull免輸入密碼方法
Enter passphrase for key '/root/.ssh/id_rsa':
[root@]#ssh-add /root/.ssh/id_rsa
若執行ssh-add /root/.ssh/id_rsa出現這個錯誤:Could not open a connection to your authentication agent,則先執行以下命令便可:
ssh-agent bash
2、
cp -Rf /home/user1/* /root/temp/
將 /home/user1目錄下的全部東西拷到/root/temp/下而不拷貝user1目錄自己。
即格式爲:cp -Rf 原路徑/* 目的路徑/
3、鉤子
倉庫同步的鉤子 hooks/post-receive
#!/bin/sh
#author: embbnux
#Blog of Embbnux: http://www.embbnux.com
#判斷是否是遠端倉庫
IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
echo >&2 "fatal: post-receive: IS_NOT_BARE"
exit 1
fi
unset GIT_DIR
DeployPath="/home/www/lin/gittest"
echo "==============================================="
cd $DeployPath
echo "deploying the test web"
git fetch --all
git reset --hard origin/master
time=`date`
echo "web server pull at webserver at time: $time."
echo "================================================"
4、pc端和linux服務器端添加public-key到碼雲上
pc端:安裝完git後公鑰路徑:C:\Users\47926\.ssh
複製文件(id_rsa.pub)的內容到=》碼雲-》設置-》SSH公鑰-》添加
linux服務器:cd ~/.ssh 複製id_rsa.pub的內容,接下來同上操做