Git rebase basics

8 messages, 3 authors, 2016-06-15 · open the first message on its own page

Git rebase basics

From: lancelyons <hidden>
Date: 2016-06-15 22:54:04

I am trying to learn git on my own.  I have setup our own server for git
using https and have cloned this repository and have done pushes and pulls
with no problem.

I am trying to learn more about rebase so i have cloned the central repo (I
call this origin)
and made changes to the cloned copy and pushed two commits to origin.

so I have the following.

origin -->  C1 --> C2

in my cloned copy which I consider a branch

I have made two more commits  C3 and C4

clone --> C3 -->  C4

I am able to easily pull from origin to get my clone to look like  clone -->
C3 --> C4 --> C1 --> C2

I was wanting to rebase the clone branch so that it shows    clone -> C1 -->
C2 --> C3 --> C4

I though the command to do this was   git rebase origin master but that
doesnt work.



Any ideas on what I am doing wrong?

thanks


--
View this message in context: http://git.661346.n2.nabble.com/Git-rebase-basics-tp7561468.html
Sent from the git mailing list archive at Nabble.com.

Re: Git rebase basics

From: Michael Witten <hidden>
Date: 2016-06-15 22:54:04

On Wed, Jun 13, 2012 at 8:59 PM, lancelyons [off-list ref] wrote:
I am trying to learn git on my own.  I have setup our own server for git
using https and have cloned this repository and have done pushes and pulls
with no problem.

I am trying to learn more about rebase so i have cloned the central repo (I
call this origin)
and made changes to the cloned copy and pushed two commits to origin.

so I have the following.

origin -->  C1 --> C2

in my cloned copy which I consider a branch

I have made two more commits  C3 and C4

clone --> C3 -->  C4

I am able to easily pull from origin to get my clone to look like  clone -->
C3 --> C4 --> C1 --> C2

I was wanting to rebase the clone branch so that it shows    clone -> C1 -->
C2 --> C3 --> C4

I though the command to do this was   git rebase origin master but that
doesnt work.



Any ideas on what I am doing wrong?

thanks
It's amazing to me that people regularly describe their problems not
with the precision of a universally reproducible sequence of command
lines, but rather with some imprecise, personal language concocted in
the very midst of using it.

Sir. You are trying to figure out how to use git commands. Why not
illustrate your difficulties by writing out a sequence of... well...
GIT COMMANDS, which everyone on this list may easily try and, most
importantly, understand with precision?

  $ git init origin
  $ cd origin
  ...

List your expected results and your actual results.

In fact, by distilling your issue into a workable example, you will
probably figure the whole thing out anyway.

Now, don't worry about writing another email. Somebody who has more
time to burn will answer your original email cordially enough (and
chastise me in the process by remarking how your scenario is
perfectly easy to understand as is).

SINCERELY,
Michael Witten

Re: Git rebase basics

From: lancelyons <hidden>
Date: 2016-06-15 22:54:04

Sorry about that.. I thought I was being pretty descriptive but maybe I
missed something.

After we setup Git (msysgit) and set it up using Apache with active
directory authentication, I added a repository using git init --bare then I
copied my files I wanted to add to the repository and did a git add . and
git commit -a

So that all worked.   We have done several clones using git clone with this
remote repo.  We have also done  git push and git pull to verify everything
is working ok.   Everything was working fine.

So back to my original train of though.

I am trying to learn more about rebase so i have cloned the central repo two
times  (I call the central repo the origin) doing the following (to help you
understand)

git clone https://servername:port/repopath c:\clonedrepo1

git clone https://servername:port/repopath c:\clonedrepo2

and then made changes to this cloned copy (clonedrepo1) and pushed two
commits back to origin.
(git commit -a  two times)

so now I have the following in the remote repo (origin)   

origin -->  C1 --> C2

(Note to help you understand  C1 = commit 1 and c2 = commit 2, etc)

In the other cloned copy (clonedrepo2), which I consider a branch, I have
made two more commits  C3 and C4

clonedrepo2 --> C3 -->  C4

I am able to easily pull from origin to get my clonedrepo2 to look like 
clonerepo2 --> C3 --> C4 --> C1 --> C2 using git pull origin  or git pull
https://servername:port/repopath

however I was wanting to rebase the clonedrepo2 branch so that it shows   
clonerepo2 -> C1 --> C2 --> C3 --> C4

In other words I am wanting to rebase clonedrepo2 to the master of the
origin.


I thought the command to do this was   git rebase origin master but that
doesnt work and I get

C:\clonedrepo2>git rebase origin master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
Current branch master is up to date.

I know my my branch is ahead by c3 and c4 but it does not have C1 and C2

Thoughts.

--
View this message in context: http://git.661346.n2.nabble.com/Git-rebase-basics-tp7561468p7561489.html
Sent from the git mailing list archive at Nabble.com.

Re: Git rebase basics

From: Hilco Wijbenga <hidden>
Date: 2016-06-15 22:54:04

On 13 June 2012 19:59, lancelyons [off-list ref] wrote:
Sorry about that.. I thought I was being pretty descriptive but maybe I
missed something.
Perhaps "descriptive" but certainly not "precise".
After we setup Git (msysgit) and set it up using Apache with active
directory authentication, I added a repository using git init --bare then I
copied my files I wanted to add to the repository and did a git add . and
git commit -a

So that all worked.   We have done several clones using git clone with this
remote repo.  We have also done  git push and git pull to verify everything
is working ok.   Everything was working fine.

So back to my original train of though.

I am trying to learn more about rebase so i have cloned the central repo two
times  (I call the central repo the origin) doing the following (to help you
understand)

git clone https://servername:port/repopath c:\clonedrepo1

git clone https://servername:port/repopath c:\clonedrepo2

and then made changes to this cloned copy (clonedrepo1) and pushed two
commits back to origin.
(git commit -a  two times)

so now I have the following in the remote repo (origin)

origin -->  C1 --> C2

(Note to help you understand  C1 = commit 1 and c2 = commit 2, etc)

In the other cloned copy (clonedrepo2), which I consider a branch, I have
made two more commits  C3 and C4

clonedrepo2 --> C3 -->  C4

I am able to easily pull from origin to get my clonedrepo2 to look like
clonerepo2 --> C3 --> C4 --> C1 --> C2 using git pull origin  or git pull
https://servername:port/repopath

however I was wanting to rebase the clonedrepo2 branch so that it shows
clonerepo2 -> C1 --> C2 --> C3 --> C4

In other words I am wanting to rebase clonedrepo2 to the master of the
origin.
What you want is "git pull --rebase origin master". See "git help
pull". Also check "git help fetch" if you really want to keep doing
this.

But it sounds like you should simply be using a real branch. You can
do "git pull" on your master branch and then run "git rebase master"
on your own branch. Did you really read up on Git? It has truly
excellent documentation. See for example http://git-scm.com/book (but
this is just one of many).
I thought the command to do this was   git rebase origin master but that
doesnt work and I get

C:\clonedrepo2>git rebase origin master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
Current branch master is up to date.

I know my my branch is ahead by c3 and c4 but it does not have C1 and C2

Thoughts.

--
View this message in context: http://git.661346.n2.nabble.com/Git-rebase-basics-tp7561468p7561489.html
Sent from the git mailing list archive at Nabble.com.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Re: Git rebase basics

From: Michael Witten <hidden>
Date: 2016-06-15 22:54:04

On Wed, 13 Jun 2012 19:59:54 -0700 (PDT), Lance
Sorry about that.. I thought I was being pretty descriptive but maybe I
missed something.

After we setup Git (msysgit) and set it up using Apache with active
directory authentication, I added a repository using git init --bare then I
copied my files I wanted to add to the repository and did a git add . and
git commit -a

So that all worked.   We have done several clones using git clone with this
remote repo.  We have also done  git push and git pull to verify everything
is working ok.   Everything was working fine.

So back to my original train of though.

I am trying to learn more about rebase so i have cloned the central repo two
times  (I call the central repo the origin) doing the following (to help you
understand)

git clone https://servername:port/repopath c:\clonedrepo1

git clone https://servername:port/repopath c:\clonedrepo2

and then made changes to this cloned copy (clonedrepo1) and pushed two
commits back to origin.
(git commit -a  two times)

so now I have the following in the remote repo (origin)   

origin -->  C1 --> C2

(Note to help you understand  C1 = commit 1 and c2 = commit 2, etc)

In the other cloned copy (clonedrepo2), which I consider a branch, I have
made two more commits  C3 and C4

clonedrepo2 --> C3 -->  C4

I am able to easily pull from origin to get my clonedrepo2 to look like 
clonerepo2 --> C3 --> C4 --> C1 --> C2 using git pull origin  or git pull
https://servername:port/repopath

however I was wanting to rebase the clonedrepo2 branch so that it shows   
clonerepo2 -> C1 --> C2 --> C3 --> C4

In other words I am wanting to rebase clonedrepo2 to the master of the
origin.


I thought the command to do this was   git rebase origin master but that
doesnt work and I get

C:\clonedrepo2>git rebase origin master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
Current branch master is up to date.

I know my my branch is ahead by c3 and c4 but it does not have C1 and C2

Thoughts.
This is what I SUPPOSE you mean (using a bash prompt):

  $ git init temp; cd temp
  $ echo 0 > a; git add a; git commit -m C0
  $ cd ..; git clone --bare temp origin; rm -rf temp
  $ git clone origin clonedrepo1
  $ git clone origin clonedrepo2
  $ cd clonedrepo1
  $ echo 1 > a; git commit -am C1
  $ echo 2 > a; git commit -am C2
  $ git push
  $ cd ../clonedrepo2
  $ echo 0 > b; git add b; git commit  -m C3
  $ echo 1 > b;            git commit -am C4
  $ # The following line is essentially `git pull',
  $ # but it would appear that `git pull' is currently
  $ # ignorant of merge's `-m' flag for specifying a
  $ # commit message on the command line.
  $ git fetch; git merge -m C5 origin/master # Essentially `git pull'
  $ git log --format=%s --graph
  *   C5
  |\  
  | * C2
  | * C1
  * | C4
  * | C3
  |/  
  * C0

Notice how the history splits at C0, and then merges back together
at C5; it's not actually the case that C1 has been made a child
of C4 (I'm guessing you have used `git log' to see a linearized
output, which does not reflect the topology of the graph).

The simplest solution would have been to tell `git pull' to perform
a rebase rather than a merge:

  git pull --rebase

We can simulate having done so by resetting our work
and pulling again:

  $ git reset --hard :/C4 # Reset back to C4; see `git help rev-parse'
  $ git branch C4 # Save this original C4 for later reference
  $ git log --format=%s --graph
  * C4
  * C3
  * C0
  $ git pull --rebase
  $ git log --format=%s --graph
  * C4
  * C3
  * C2
  * C1
  * C0

The line:

  git pull --rebase

Is essentially just the same as before, except that a rebase
rather than a merge is performed, essentially equivalent to
the following:

  git fetch; git rebase origin/master

which is something you could certainly do by hand to fix
the problem without performing the additional fetch:

  $ git reset --hard C4 # Go back to the original C4 commit
  $ git rebase origin/master

Sincerely,
Michael Witten

Re: Git rebase basics

From: lancelyons <hidden>
Date: 2016-06-15 22:54:07

Thanks Hilco,

git pull --rebase origin master    gave me the desire results.   Thanks

I am still wondering why git rebase origin master did not.

I was thinking that this command would rebase the cloned repository I was in
and rebase it to the master of the origin.

in my scenario  what would git rebase origin master  be doing?

Again thanks

--
View this message in context: http://git.661346.n2.nabble.com/Git-rebase-basics-tp7561468p7561538.html
Sent from the git mailing list archive at Nabble.com.

Re: Git rebase basics

From: Michael Witten <hidden>
Date: 2016-06-15 22:54:07

On Thu, Jun 14, 2012 at 4:01 PM, lancelyons [off-list ref] wrote:
in my scenario  what would git rebase origin master  be doing?
I suggest reading the documentation for `git rebase'.

Re: Git rebase basics

From: lancelyons <hidden>
Date: 2016-06-15 22:54:07

Hey Michael,   Thanks thats good information there.

--
View this message in context: http://git.661346.n2.nabble.com/Git-rebase-basics-tp7561468p7561545.html
Sent from the git mailing list archive at Nabble.com.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help