0

I have a working copy of the Android source tree that I have used to compile from. I want to sync the latest changes from the repo (any new things they have done) but I get an error that

"You have local changes to 'kernel'; cannot switch branches."
"You have local changes to 'products/common.mk; cannot switch branches."

then I get presented 2 errors at what I assume is the end (it seems to have done one more line of tree syncing after that).

So, my question is, how do I sync their changes on top of things I have changed locally? I cannot commit a change because I am not a contributor to the project, I want to keep my changes local.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Hamid
  • 4,410
  • 10
  • 43
  • 72
  • possible duplicate of [Git: automatically keep a secondary repo in sync with a primary repo?](http://stackoverflow.com/questions/3669636/git-automatically-keep-a-secondary-repo-in-sync-with-a-primary-repo) – Mogsdad Aug 25 '15 at 01:50

3 Answers3

2

Your question is actually a commonly encountered situation in git - making localized changes using git.

When you use git pull, you only get the diff between the local git image and the remote git server. whenever you make local changes, you can issue git diff to see the differences. So for you your steps should be:

  1. git diff > mydiff.patch to get a patch difference of the changes u have made.
  2. git checkout -f to revert back to the original image before your localized changes.
  3. git pull to do a full git update from remote server. this is where repo sync can come in as well - as repo sync drop to basically a sequence of git command (viewed via ps -ef)
  4. then you re-apply your localized changes again via patch -p1 --dry-run < mydiff.patch to test out the reapplication. If successful, do the real patching via:

    patch -p1 < mydiff.patch
    

    If not successful, it only means that your changes is conflicting with some changes done on the remote server side that others have committed, and this is where you have to manually redo your changes again - tedious but no choice.

Take note: git can be applied at each directory where you see a .git directory, and the git command only take effect at that directory level. If you have make multiple changes in different directories with .git subdirectory, then you have do a git diff and git checkout -f for each of those directory.

For example, while doing a repo sync update I got:

Fetching projects: 100% (172/172), done.  
Syncing work tree:   2% (4/171)  error: You have local changes to 'core/base_rules.mk'; cannot switch branches.
Syncing work tree:   3% (6/171)  error: You have local changes to 'tools/dx-tests/Android.mk'; cannot switch branches.
Syncing work tree: 100% (171/171), done.  

external/dbus/: discarding 43 commits
error: build/: platform/build checkout 0683a77348f2a0a529a8e2bcfdf4b6dc6b4c5f5b 
error: cts/: platform/cts checkout a3779fa378345bfd8699e91de46b29563be4beb2 

Traversing downwards, I discovered that under the cts directory is a .git, so cd cts and git diff gives the difference.

The above scheme is simple enough, as there is always only one branch - the master branch, and your changes is always on top of that.

Alternatively you have to use git branch to build your own branch, and then git merge to merge your branch into the default master branch (read this).

The command for merging will be git merge topic, where topic is the branch created with git branch to house your customized changes.

Overall the operations are still the same as above - conflicts will occur if the master and your branch modify the same file at the same line, or your modification comes AFTER the master.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Peter Teoh
  • 6,337
  • 4
  • 42
  • 58
0

You can use another branch for your changes... or try git pull --rebase

mrutyunjay
  • 6,850
  • 7
  • 25
  • 35
0

While I've not used git much and I'm assuming from the advisory messages that you are accessing a git repo, I believe the tool is simply refusing to overwrite your local changes .. which is a good thing, yes? I think things are happening exactly as you wish them to happen, unless you'd like to flip between your local work and the latest repo view.

Perhaps this guide (on SO) Git for Beginners: The definitive practical guide may be some help.

Community
  • 1
  • 1
David J. Liszewski
  • 10,959
  • 6
  • 44
  • 57
  • Yep, it was purely a lack of understanding on my part. I am unfamiliar with the workings of distributed source control systems (being used to subversion). – Hamid Jan 06 '11 at 12:30