強制拉取分支到本地
~~~
git reset --hard origin/main
git pull origin main
~~~
項目根目錄初始化git倉庫\`\`
```
git init
```
將本地項目與遠程倉庫關聯\`\`
```
git remote add origin https://gitee.com/lingliangxing/ruyibang.git
```
拉取遠程倉庫代碼
```
git pull origin master
git push -u origin master
這會將本地的 master 分支推送到遠程倉庫,并建立跟蹤關系。
```
將本地對應分支強制重置為線上分支\`\`
```
git reset --hard origin/maste
```
基于當前分支創建新分支:
~~~
$ git branch <new-branch>
~~~
設置本地分支追蹤遠程分支
```
git branch --set-upstream-to=origin/develop develop
```
添加并提交
```
git commit -am ''
```
創建并切換分支
```
git checkout -b dev
```
一鍵上傳
```
git add . ; git commit -m "人臉支付調整"; git pull; git push
```
解決沖突
```
git stash: 將改動藏起來
git pull:用新代碼覆蓋本地代碼
git stash pop: 將剛藏起來的改動恢復這樣操作的效果是在最新的倉庫代碼的基礎仍保留本地的改動
```
```
git config --global user.email "13265990757@sina.cn
git config --global user.name "lingliangxing
```
放棄本地文件所有的文件修改,拉取覆蓋
```
git checkout .
```
強制拉取覆蓋
~~~
git reset --hard origin/master
git pull
~~~
~~~
git config --global user.name "llxllx"
git config --global user.email "13265990757@sina.cn"
~~~
******git移除控制目錄******
```
git rm -r --cached public/store
```
Git 服務器自動拉取
```
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
gitPath="/www/wwwroot/yanqixi"
step=8 #間隔的秒數,不能大于60
for (( i = 0; i < 60; i=(i+step) )); do
cd $gitPath;git checkout .;git pull
echo "----------------------------------------------------------------------------"
echo "設置目錄權限"
sudo chown -R www:www $gitPath
echo "End"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep $step
done
exit 0
```
```
#### 簡易的命令行入門教程:
Git 全局設置:
~~~
git config --global user.name "llxllx"
git config --global user.email "13265990757@sina.cn"
~~~
創建 git 倉庫:
~~~
mkdir sfs
cd sfs
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin?https://gitee.com/lingliangxing/sfs.git
git push -u origin "master"
~~~
已有倉庫?
~~~
cd existing_git_repo
git remote add origin?https://gitee.com/lingliangxing/sfs.git
git push -u origin "master"
~~~
```
## webhook
```
#!/bin/bash
echo ""
#輸出當前時間
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#git項目路徑
gitPath="/www/wwwroot/yanqixi"
echo "Web站點路徑:$gitPath"
#判斷項目路徑是否存在
if [ -d "$gitPath" ]; then
cd $gitPath
echo "拉取最新的項目文件"
#sudo git reset --hard origin/master
sudo git reset --hard origin/master
sudo git checkout .
output=$(sudo git pull)
echo $output
echo "設置目錄權限"
sudo chown -R www:www $gitPath
echo "End"
exit
else
echo "該項目路徑不存在"
echo "End"
exit
fi
```
###
### 忽略當前目錄所有文件
```
*
!.gitignore
```
#### 保存登錄的git 賬號密碼只登錄一次
```
git config --global credential.helper store
```
### 使用以下命令將該文件夾從 Git 中移除:
```
git rm -r --cached
```
## 忽略指定文件不生效執行
```
git rm .env --cached
```
##
## 全局設置默認分支名稱
```
git config --global init.defaultBranch main
```