1. gitignore文件不起作用的解决方案:
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
2. 拉取线上特定的分支(如:克隆dev分支的代码):
git clone -b dev git-url
// 在本地创建分支dev并切换到该分支
git checkout -b dev(本地分支名称) origin/dev(远程分支名称)
注:
①. -b表示要从分支下载.
②. dev是具体某个分支的名称.
3. 初始化本地已有的项目上传到新仓库:
# 把远端仓库中的代码拉到本地进得合并一下:
git pull --rebase origin master
注:
①. rebase操作不会生成新的节点,是将两个分支融合成一个线性的提交.
(1). 初始化已有的项目:
$ git init
$ git add .
$ git commit -m "push current files"
// 将本地仓库与远程仓库关联起来
$ git remote add origin git@github.com:xxx.git
// pull远程仓库的内容、更新本地仓库.
// –allow-unrelated-histories会忽略本地仓库和远程仓库的无关性,强行合并
$ git pull origin master --allow-unrelated-histories
// 把本地仓库的内容push到远程仓库:
$ git push -u origin master
4. git初始化:
①. Existing folder:
git init
git remote add origin git@xxxxxx/gin-data.git
git add .
git commit -m "Initial commit"
git push -u origin master
②. Existing Git repository:
git remote remove origin
git remote add origin git@xxxxx/gin-data.git
git push -u origin --all
git push -u origin --tags
4. 去掉本地修改:
git reset -–hard
5. git报错:
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
// 解决办法:
$ git config pull.ff false
$ git config --global pull.rebase false