git-bash的一些操做命令

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的内容,接下来同上操做

相关文章
相关标签/搜索