我查了一下开发部门的一个叫 branch-x的功能分支。过了一段时间,其他人推动了开发分支的变更。
branch-x
我想合并这些变化到我的 branch-x。然而,如果我这样做
git merge develop
上面写着“已经更新”而且不允许我合并。
git diff develop表明 branch-x与发育有差异。
git diff develop
如何合并发展成为 branch-x?
You should first pull the changes from the develop branch and only then merge them to your branch:
pull
develop
git checkout develop git pull git checkout branch-x git rebase develop
Or, when on branch-x:
git fetch && git rebase origin/develop
I have an alias that saves me a lot of time. Add to your ~/.gitconfig:
~/.gitconfig
[alias] fr = "!f() { git fetch && git rebase origin/"$1"; }; f"
Now, all that you have to do is:
git fr develop
Initially my repo said "Already up to date."
MINGW64 (feature/Issue_123) $ git merge develop
Output:
Already up to date.
But the code is not up to date & it is showing some differences in some files.
MINGW64 (feature/Issue_123) $ git diff develop
diff --git a/src/main/database/sql/additional/pkg_etl.sql b/src/main/database/sql/additional/pkg_etl.sql index ba2a257..1c219bb 100644 --- a/src/main/database/sql/additional/pkg_etl.sql +++ b/src/main/database/sql/additional/pkg_etl.sql
However, merging fixes it.
MINGW64 (feature/Issue_123) $ git merge origin/develop
Updating c7c0ac9..09959e3 Fast-forward 3 files changed, 157 insertions(+), 92 deletions(-)
Again I have confirmed this by using diff command.
diff
No differences in the code now!
git fetch && git merge origin/develop
git pull origin develop
Since pulling a branch into another directly merges them together
Step by step self explaining commands for update of feature branch with the latest code from origin "develop" branch:
git checkout develop git pull -p git checkout feature_branch git merge develop
If there are any merge conflicts after "git merge" CMD, fix the merge issues manually & add those manually merged file(s) & commit
git add <mergedFile> git commit -m "Merged develop to feature_branch"
Finally push the merge to remote:
git push origin feature_branch