执行git stash
保存后,git status
将显示无任何改动。html
git stash # Temporarily stores all modified tracked files git stash list # Lists all stashed changesets git stash pop <stash> # Restores the stashed files, and delete the stashed files. git stash apply <stash> # Restores the stashed files, and reserve the stashed files. git stash drop # Discards the most recently stashed changeset git stash show # Show the latest changes recorded in the stash as a diff between the stashed state and its original parent. git stash clear # Remove all the stashed states.
不一样的人修改同个文件的同一个地方,而后推送到远程库是会发生“推送失败”,由于推送有冲突。
解决方法:先用git pull
抓取最新的提交,而后在本地合并,解决冲突,再推送。
使用git pull
前,必须指定本地branch分支与远程origin/branch分支的连接(git branch --set-upstream-to
)git
尝试用git push origin <branch name>
推送修改。
若是推送失败,可能由于远程分支比本地更新早,使用git pull
试图合并。
若是合并有冲突,则须要解决冲突,并在本地提交,再用git push origin <branch name>
推送。windows
Local配置优先级高于global配置,并且Local的配置必须在local repository目录下完成。
示例:安全
$ git config --local user.name "anliven" # 配置local repository的用户名 $ git config --local user.email "anliven@yeah.net" # 配置local repository的邮箱 $ git config --local --list # 显示local repository配置信息 $ git config --local --unset [value-regex] # 去除local repository配置 $ git config --local --edit # 交互式local repository配置
Git配置文件优先级:local > global > system
bash
配置文件 | 有效范围 | 查看 | 配置方法 | 名称及目录 |
---|---|---|---|---|
local | 本地仓库 | git config --local --list | git config --local --edit | 本地仓库目录下,例如:<local repository>\.git\config |
global | 全部仓库 | git config --global --list | git config --global --edit | 用户目录下,例如:C:\Users\xxx.gitconfig |
system | 不建议改动 | git config --system --list | git config --system --edit | git的安装目录下,例如:C:\Program Files\Git\mingw64\etc\gitconfig |
利用git rebase -i
把其它commits标注为squash,从而将其它commits并入一个commit。
合并多个 Commit
合并 commit 保持分支干净整洁app
link
git pull = git fetch + git merge
git pull --rebase = git fetch + git rebase
fetch
# 在相应Repository目录中查看文件权限 git ls-tree HEAD # 修改权限(权限修改后,至关于文件进入了index) git update-index --chmod=+x <test.sh> # 提交修改 git commit -m "script permission update" # 确认修改结果 git ls-tree HEAD
^M: bad interpreter
检查文件格式,必要时使用dos2unix命令转换文件格式。
在windows git下,建议关闭自动换行,并启用安全换行检查。ui
# 关闭自动换行的设置 git config --global core.autocrlf false # 启用安全换行符检查 git config --global core.safecrlf true
默认状况下,git将忽略空文件夹,也就是说空文件夹没法加入到repository。
解决办法:在空文件夹下建立包含!.gitignore
内容的.gitignore
文件便可。.net