git-bash的一些操作命令

一、操作git-bash

1、添加 git add 11.txt 22.txt 33.txt

2、提交 git commit -m "add wenjian"

3、git push 提交到远程服务器(第一次push:git push origin master)

4、如果版本号对应不上又提交不了(error: Your local changes to the following files would be overwritten by merge:  )

方法1:如果你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)

git stash  
git pull origin master  
git stash pop  

方法2、如果你想完全地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull:

git fetch --all
git reset --hard origin/master

5、企业协同时

  1)、 git checkout lzh //切换到自己分支;

  2)、 git merge --no-ff develop //把develop的修改merge到 lzh

  3)、再git push origin lzh //在自己分支上提交,看是否有冲突,并处理冲突

  4)、git push origin develop //正式提交到develop

 6、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

二、

cp -Rf /home/user1/* /root/temp/
将 /home/user1目录下的所有东西拷到/root/temp/下而不拷贝user1目录本身。
即格式为:cp -Rf 原路径/* 目的路径/

三、钩子

仓库同步的钩子 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 "================================================"

四、pc端和linux服务器端添加public-key到码云上

  pc端:安装完git后公钥路径:C:Users47926.ssh

    复制文件(id_rsa.pub)的内容到=》码云-》设置-》SSH公钥-》添加

  linux服务器:cd ~/.ssh  复制id_rsa.pub的内容,接下来同上操作

原文地址:https://www.cnblogs.com/makeinchina/p/8038875.html