*这是其中之一“这是个好主意吗?” 我无法真正格式化为可接受的问题的问题,但是....
我仍然对 git 不是 100% 满意,特别是与远程分支合并。如果出现问题或者我只想放弃一堆合并冲突,我通常会努力回滚合并/提交。可以这么说,我发现自己离兔子洞更远了。我想知道,创建一个分支只是为了进行远程合并然后在本地将临时分支与我的“真实”分支合并起来会更容易吗?这样,如果出现问题,我总是可以核对临时分支。
更新:我对我的远程分支何时将一堆文件添加到我的仓库特别感兴趣。例如(使用下面彼得的例子):
我这样做:
$ git init
Initialized empty Git repository in /path/to/repo/.git/
$ touch README
$ git add README
$ git commit -m 'Initial commit'
[master (root-commit) da9886d] Initial commit
0 files changed
create mode 100644 README
$ touch A
$ git add A
$ git commit -m 'Add A'
[master 3480a5b] Add A
0 files changed
create mode 100644 A
$ git push // pushed to remote (only a single file, A)
然后另一个开发人员这样做:
$ git clone
$ touch B
$ git add B
$ git commit -m 'Add B'
[foo 9912a23] Add B
0 files changed
create mode 100644 B
$ git push // pushed to remote (now has two files A and B)
如果我这样做:
$ git pull
我将有两个文件 A 和 B。现在如果我想“退后一步”并撤消合并:
$ git reset --hard master@{...}
文件 B 仍将作为未跟踪文件存在于我的机器上,对吗?我怎样才能退后一步并删除这些文件,就好像我从未进行过 git 合并一样?
这就是为什么我希望创建一个单独的分支。如果我创建一个单独的分支来进行合并:
$ git checkout -b tempBranchForMerge
$ git pull
我仍然得到文件 A 和 B,但它们只存在于 tempBranchForMerge 上。如果出现问题,我应该可以这样做:
$ git checkout master
$ git branch -d tempBranchForMerge
正确的?这将删除文件 B。