Git中的git reset的三种参数的区别

我们平时在使用git的时候,经常会遇到需要撤销上次操作的需求,这时候需要用到git reset的这个命令,他的使用就是 “git-reset – Reset current HEAD to the specified state”, 注意这里主要操作的就是这个 HEAD

为了方便我们先了解一下 Git 的工作流程

相信大家对这个图已经很熟悉了,其中index也叫stage暂存区或者暂存索引区。git reset 共有三个互斥参数分别为”–soft”、”–mixed(默认参数)” 和 “–hard”,每种参数表示一种恢复模式,下面我们将分别看一下这git reset 三个参数的用法区别。 Continue reading

git无法pull仓库refusing to merge unrelated histories的解决办法

在本地有一个很久的项目,需要上传到远程git仓库中,先在远程创建了一个仓库,在本地配置好后,发现上传的时候,提示先git pull 一下,但git pull的时候提示这个错误,主要是因为目前两个git仓库信息不一致问题,我们要将两个项目合并在一起,需要添加一个  –allow-unrelated-histories 参数即可。

先进入cli命令行模式,执行

git pull origin master --allow-unrelated-histories

然后再执行git pull origin master 即可。

参考:http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories

在linux下,解决修改文件权限引起的git出现的文件变化问题

有时候,我们将服务器上的web文件夹的权限进行了修改,但git默认是也会记录权限状态的,这个时间用git status会发现所有的文件都处于被修改的状,这显示不是我们想要的。这时我们只要让git把文件权限忽略掉就可以了。

在操作前首先我们确认一下当前配置项core.filemode,默认为true,(也可以使用cat .git/config查看)

$ git config --list

然后执行

$ git config core.filemode false

这样就设置了忽略文件权限。查看下配置:

$ cat .git/config

git%e5%bf%bd%e7%95%a5%e6%96%87%e4%bb%b6%e6%9d%83%e9%99%90%e7%9a%84%e9%85%8d%e7%bd%ae
git忽略文件权限的配置

 

解决git clone时报错:The requested URL returned error: 401 Unauthorized while accessing的问题

版本问题,最直接的解决办法就是重新编辑安装git吧:

1. 下载:

wget -O git.zip https://github.com/git/git/archive/master.zip

2. 解压:

unzip git.zip

3. 进入git目录:

cd git-master

4. 编译安装:

autoconf
./configure --prefix=/usr/local
make && make install

5. 最后别忘了删掉旧的git,并把新版本的git建立软链接到/usr/bin/git

rm /usr/bin/git
ln -s /usr/local/bin/git /usr/bin/git

 

git提示“Pull is not possible because you have unmerged files.”的解决办法(转)

在git pull的过程中,如果有冲突,那么除了冲突的文件之外,其它的文件都会做为staged区的文件保存起来。

重现:

$ git pull

A    Applications/Commerce/BookingAnalysis.java
A    Applications/Commerce/ClickSummaryFormatter.java
M    Applications/CommerceForecasting/forecast/Forecast.java
A    Applications/CommerceForecasting/forecast/ForecastCurveProviderCategory.java
M    Applications/CommerceForecasting/forecast/ForecastProvider.java
M    Applications/CommerceForecasting/forecast/InputPropertyItem.java
……

A    Applications/LocalezeImporter/com/tripadvisor/feeds/SingleMenuLocalezeMatcher.java
A    Applications/LocalezeImporter/com/tripadvisor/feeds/TypeCategory.java

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use ‘git add/rm <file>’
as appropriate to mark resolution, or use ‘git commit -a’.

通过git status你会发现下面古怪的事情:

zhonghua@pts/ttys000 $ git status
# On branch sns
# Your branch and ‘snsconnect/sns’ have diverged,
# and have 1 and 52 different commit(s) each, respectively.
#
# Changes to be committed:
#
#    new file:   src/config/features_daodao.ini
#    new file:   src/config/services.xml
#    new file:   src/config/svnroot/hooks/mailer.conf
#    new file:   src/config/svnroot/hooks/mailer.py
#    new file:   src/config/svnroot/hooks/post-commit
#    new file:   src/config/svnroot/hooks/pre-commit
#    new file:   src/config/svnroot/hooks/prerelease_notifications.py
#    new file:   src/config/svnroot/hooks/run_checks.py
…….

# Untracked files:
#   (use “git add <file>…” to include in what will be committed)
#
#    _build/
#    css/combined/
#    css/gen/
#    daodao-site.patch
#    daodao-site.patch1
#    js/combined/
#    js/gen/
#    lib/weibo/
#    src/bin/

Pull is not possible because you have unmerged files.

解决:

1.pull会使用git merge导致冲突,需要将冲突的文件resolve掉 git add -u, git commit之后才能成功pull.

2.如果想放弃本地的文件修改,可以使用

git reset –hard FETCH_HEAD

FETCH_HEAD表示上一次成功git pull之后形成的commit点。然后git pull.
注意:

git merge会形成MERGE-HEAD(FETCH-HEAD) 。git push会形成HEAD这样的引用。HEAD代表本地最近成功push后形成的引用。

参考:http://www.ithao123.cn/content-4783203.html

Git-svn命令对比表,svn用户必看

提供给从svn转git的开发人员参考

Git与Subversion的命令对比表

操作 Git Subversion
复制数据仓库 git clone svn checkout
提交 git commit svn commit
查看提交的详细记录 git show svn cat
确认状态 git status svn status
确认差异 git diff svn diff
确认记录 git log svn log
添加 git add svn add
移动 git mv svn mv
删除 git rm svn rm
取消修改 git checkout / git reset svn revert (※1)
创建分支 git branch svn copy (※2)
切换分支 git checkout svn switch
合并 git merge svn merge
创建标签 git tag svn copy (※2)
从服务端更新本地 git pull / git fetch svn update
推送到远端 git push svn commit (※3)
忽略档案目录 .gitignore .svnignore

※1. SVN的revert是用来取消修改,但Git的revert是用来消除提交。所以即使是同样的命令,在SVN和Git里的含义是不同的。

※2. SVN的分支与标签在构造上是相同的,但在Git其构造明显是不一样的。

※3. SVN没有本地数据库/远程数据库的概念,所以提交会马上反映到远程里。但Git的本地数据库和远程数据库的反映方法是不一样的。

使用 Git Hook 实现网站的自动部署

自动化能解放人类的双手,而且更重要的是,因为按照规定的流程来走,也减少了很多误操作的产生。不知道大家平时都是怎么样更新自己生产环境的代码的,FTP 覆盖旧文件、服务器定时任务去 build 最新的源码,还是有更高级的做法?

目前我在使用 Git Hook 来部署自己的项目。Git Hook 是 Git 提供的一个钩子,能被特定的事件触发后调用。其实,更通俗的讲,当你设置了 Git Hook 后,只要你的远程仓库收到一次 push 之后,Git Hook 就能帮你执行一次 bash 脚本。 Continue reading

Git中的hooks钩子

Git可以定制一些钩子,这些钩子可以在特定的情况下被执行,分为Client端的钩子和Server端的钩子。
Client 端钩子被operation触发,比如commit,merge等
Server 端钩子被网络动作触发,比如pushed commits。

那么钩子是放在哪的呢?

在.git/hooks/文件夹下。当你init一个仓库的时候,下边会有一些钩子的例子,以.sample结尾。

那么钩子什么时候被执行,Git预定义了触发时机:

ClientSide hooks:

1 pre-commit,当执行commit动作时先执行此hook,可以用此hook做一些检查,比如代码风格检查,或者先跑测试。 Continue reading