第1个问题: 解决GIT代码仓库不同步
今天在执行git pull时出现:
- [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git pull
- Enter passphrase for key '/root/.ssh/id_rsa':
- Updating 70e8b93..a0f1a6c
- error: Your local changes to the following files would be overwritten by merge:
- rest/lib/Business/Inventory/ProductStatus.php
- Please, commit your changes or stash them before you can merge.
- Aborting
解决方法:
执行git checkout -f,然后再执行git pull重新checkout
- [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git checkout -f
- Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
再执行git pull时就可以了:
- [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git pull
- Enter passphrase for key '/root/.ssh/id_rsa':
- Updating 70e8b93..a0f1a6c
- Fast-forward
- rest/lib/Business/Inventory/ProductStatus.php | 1 +
- 1 files changed, 1 insertions(+), 0 deletions(-)
- mode change 100644 => 100755 rest/lib/Business/Inventory/ProductStatus.php
第2个问题: git pull的默认地址问题.
1.git处于master这个branch下时,默认的remote就是origin;
2.当在master这个brach下使用指定remote和merge的git pull时,使用默认的remote和merge。
但是对于自己建的项目,并用push到远程服务器上,并没有这块内容,需要自己配置。
如果直接运行git pull,会得到如此结果:
#当执行git pull之后的提示:
- $ git pull
- Password:
- You asked me to pull without telling me which branch you
- want to merge with, and 'branch.master.merge' in
- your configuration file does not tell me, either. Please
- specify which branch you want to use on the command line and
- try again (e.g. 'git pull <repository> <refspec>').
- See git-pull(1) for details.
- If you often merge with the same branch, you may want to
- use something like the following in your configuration file:
- [branch "master"]
- remote = <nickname>
- merge = <remote-ref>
- [remote "<nickname>"]
- url = <url>
- fetch = <refspec>
- See git-config(1) for details.
#解决方法, 通过git config进行如下配置.
- git remote add -f origin git@192.168.21.44:rest.git
- git config branch.master.remote origin
- git config branch.master.merge refs/heads/master
今天经过老大的指点,终于一解困惑我多年的这个问题:
使用git时候,本地新建分支, push到remote上去后,再次pull下来,会报以下提示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
You asked me to pull without telling me
which
branch you
want to merge with, and
'branch.production.merge'
in
your configuration
file
does not tell me, either. Please
specify
which
branch you want to use on the
command
line and
try again (e.g.
'git pull <repository> <refspec>'
).
See git-pull(1)
for
details.
If you often merge with the same branch, you may want to
use something like the following
in
your configuration
file
:
[branch
"production"
]
remote = <nickname>
merge = <remote-ref>
[remote
"<nickname>"
]
url = <url>
fetch = <refspec>
See git-config(1)
for
details.
|
之前都是按照提示手动配置的,一直在寻找利用口令直接配置的方法,经过老大指点,问题轻松解决:
1
|
git branch --
set
-upstream production origin
/production
|
结果是在项目目录下 .git/config中添加如下内容,也就是之前我一直手动添加的代码:
1
2
3
|
[branch
"production"
]
remote = origin
merge = refs
/heads/production
|
man git branch如下:
1
|
When a
local
branch is started off a remote-tracking branch, git sets up the branch so that git pull will appropriately merge from the remote-tracking branch. This behavior may be changed via the global branch.autosetupmerge configuration flag. That setting can be overridden by using the --track and --no-track options, and changed later using git branch --
set
-upstream.
|
git fetch --all
git reset --hard origin/master
git fetch origin --prune 更新本地分之与远程同步。
强制覆盖本地文件