How do developers manage to code a single file constantly being pushed and pulled on git? -
for example, i'm wondering how developers work on single file together, without stepping , tripping on each other. possible code single file @ same time else (without them sitting in chair next @ same computer, of course)? if so, how not mess up? (for example, imagine make change in same place else makes change, @ same time, , push different changes git).
so end-all question this: possible multiple people work on same source file simultaneously? if so, how?
this may not perfect specific-type question stack overflow, i'm giving shot.
i use git productively, try answer question possible:
almost sourcecode management systems maintain sort of "history". history sequential collection of commits have been made repository. commit has id , core-delta represents. commit delta, never snapshot of whole repository. can imagine history one-dimensions write-only-stack. can ever put commits (changes) on top of it, never remove one, nor put 2 things aside of each other. has copy(clone) of repository has own local history. in means, commit depending on commit has been done before it. note remote repository has history well. more later.
when make change in local copy, putting new commit on top of local history-stack (i believe why git calls local modifications "head" - because "on top" of else). left stack local history, right 1 history of remote repository. a, b, c, d , e old commits , remote repository know about. let's say, x new, local commit want push remote repository:
| | | | | x | | | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote if push commit remote repository, pushing id's of commits in local history, new commit on top of old changes. server try match commits point made change (in git terms, is said, , server "diverged").
change: | | | | | x | | | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote push: | | | | | x | -------> | | | e | -------> | e | | d | -------> | d | | c | -------> | c | | b | -------> | b | | | -------> | | ----- ----- remote check: | | | | | x | new ---> | | | e | <- ok -> | e | | d | <- ok -> | d | | c | <- ok -> | c | | b | <- ok -> | b | | | <- ok -> | | ----- ----- remote if both histories match (up change on top of that), server accept change , merge it. both histories in sync again, no longer "diverged". so:
merged: | | | | | x | | x | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote coming question:
if 2 developers edit local copy @ same time , 1 of them pushes his/her change, remote repository updated. have 1 more commit copy have locally. not limited 1 file, whole repository.
if try push local commit after developer has pushed else, local history different 1 of remote server. using above illustration again, want show whan happenes on server:
developer (push successful): | | | | | x | -----------> | | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote developer b (push error): | | | | | y | ---- ?? ---> | x | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote the remote server reject submitted change because cannot resolve dependency of commit. commit depends on commit "e", trying put on top of different commit "y" (which destroyed in commit "e", knows?)
in order solve kind of issue, developers have make sure "in sync" remote repository want push to, before pushing local commit.
in git git fetch latest history updates remote repository , git rebase put local changes (your head) ontop of changes have been made on remote server. action change local history match 1 of remote repository:
before: | | | | | | | g | | y | | f | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote after fetch + rebase: | y | | | | g | <----------- | g | | f | <----------- | f | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote push successful: | y | -----------> | | | g | | g | | f | | f | | e | | e | | d | | d | | c | | c | | b | | b | | | | | ----- ----- remote you can push local changes without problems.
note process of rebasing not automatic. if local history , remote history "conflict" (in git editing same lines in same file), have manually "resolve" conflict before rebase can succeed. means you, developer b, have manually choose, 1 correct change use.
for question means, 2 developers can of course edit same file simultaneously. when want push changes central repository, latter 1 have resolve possible "conflicts" of code previous committer.
i hope small explanation you.
please gentle, first post on stackoverflow =)
Comments
Post a Comment