Git: использование stash и rebase для обновления локального бранча

Автор: | 07/06/2015

git-logoИмеется локальный бранч, созданный из develop.

После его создания – в develop было сделано много изменений, и перед созданием pull-реквеста – хочется их синхронизировать.

Отличная документация по rebase и merge есть тут>>>.

Для того, что бы не потерять изменения, которые мы уже сделали в локальном бранче – сначала выполняем stash:

d:***plugins>git stash
Saved working directory and index state WIP on NG-5071-add-propertygroup-to-csproj-file: 14a423c Merged in upldate_plugins_sln (pull request #1097)
HEAD is now at 14a423c Merged in upldate_plugins_sln (pull request #1097)

Если бранч develop не загружен – загружаем:

d:***plugins>git pull origin develop

Объединяем бранч с “главным” бранчем – в данном примере это develop:

d:***plugins>git rebase origin/develop
First, rewinding head to replay your work on top of it...
Fast-forwarded NG-5071-add-propertygroup-to-csproj-file to origin/develop.

Возвращаем наши изменения из stash:

d:***plugins>git stash pop
On branch NG-5071-add-propertygroup-to-csproj-file
Your branch is ahead of 'origin/NG-5071-add-propertygroup-to-csproj-file' by 8 commits.
(use "git push" to publish your local commits)

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: Plugins/AbstractGUI/AbstractGUI.csproj
modified: Plugins/AnimationFlyer/AnimationFlyer.csproj
...
modified: Plugins/UnityUI_Api/UnityUI_Api.csproj
modified: Plugins/WalkingNavigation/WalkingNavigation.csproj

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (11e43ec11678eb5f953fe6ceffdad3261346453f)

Проверяем статус:

d:***plugins>git status
On branch NG-5071-add-propertygroup-to-csproj-file
Your branch is ahead of 'origin/NG-5071-add-propertygroup-to-csproj-file' by 8 commits.
(use "git push" to publish your local commits)
...

modified: Plugins/AbstractGUI/AbstractGUI.csproj
modified: Plugins/AnimationFlyer/AnimationFlyer.csproj
...
modified: Plugins/UnityUI_Api/UnityUI_Api.csproj
modified: Plugins/WalkingNavigation/WalkingNavigation.csproj

no changes added to commit (use "git add" and/or "git commit -a"

Добавляем изменения:

d:***plugins>git add -A

Комитим:

d:***plugins>git commit -m "NG-5071 Add <PropertyGroup> to .csproj files"
[NG-5071-add-propertygroup-to-csproj-file 94ca007] NG-5071 Add <PropertyGroup> to .csproj files
63 files changed, 425 insertions(+), 339 deletions(-)

И сохраняем все обновления и наши изменения:

d:***plugins>git push origin