git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: bug report

From
李李本超 <libenchao@gmail.com>
Date
May 13, 2016, 06:57 UTC
Message-ID
<CABKuJ_SEK-t93sCmj6aFSAbk8muX_ocQx6ZQZV3ZrNmvVmvDQA@mail.gmail.com>
In-Reply-To
<CAFZEwPP32vWrCA9H+JbFineodDtGx2_bTjGy-nZ9KW2v8bP5vQ@mail.gmail.com>
Yes, you got the right understanding of my problem.

You are right, the git behavior is quite correct. But I met this problem in my practical work:

My colleague added a method but I didn't know. I also added the same method. Then I found that I didn't need the method actually, so I deleted it. My colleague merged to the master before me. When I wanted to merge, I found conflicts with master. And I rebased to current master. And That method was deleted finally without any warning or information.

Do you think Git should output something to warn the user or I just use Git in a wrong way ?

Thanks.
2016-05-13 14:37 GMT+08:00 Pranit Bauva <pranit.bauva@gmail.com>:
Show 56 quoted lines
> On Fri, May 13, 2016 at 11:28 AM, 李本超 <libenchao@gmail.com> wrote:
>> git version 2.6.4 (Apple Git-63)
>> system version: OS X EI Capitan 10.11.4
>>
>> below is the steps:
>> $ mkdir test_repo
>> $ cd test_repo
>> $ git init
>> $ echo "hello" > README.md
>> $ git commit -a -m 'Add README.md'
>
> It was my mistake. git-commit -a adds files which are tracked.
> Currently README.md is not tracked. So you will have to first use
> git-add to add them for tracking. Though while trying out your steps I
> used git-add. For further commits one can use -a with git-commit.
>
>> $ git checkout -b A
>> $ echo "world" > README.md
>> $ git commit -a -m 'Add one line'
>
> You are technically not adding a line. You are modifying the previous
> line to the updated line. So the contents of the file will be:
> "world"
> It seems from the further part that you actually wanted to add the
> line rather than modifying it. Better to use ">>" instead of ">". ">>"
> is used for appending.
>
>> $ git checkout master
>> $ git checkout -b B
>> $ echo "world" > README.md
>> $ git commit -a -m 'Add one line too'
>> $ [midify 'world' line to other things like 'git' using vi]
>
> I think you mean modify.
>
>> $ git commit -a -m 'Modify one line'
>>
>> $ git checkout master
>> $ git merge A
>>
>> $ git checkout B
>> $ git rebase master [problem is here, cat README.rd we will get :
>> hello and git instead of hello world git]
>
> The git behavior is quite correct.
> When you are on the B branch and you choose to rebase it on the
> master, it will apply commits as patches. So it first sees that the
> commit on the A branch which is now merged with master ie. "Add one
> line" and the commit on the B branch "Add one line too" are doing the
> same thing which is removing the line "hello" and adding the line
> "world". Then it applies the commit "modify one line" on top of this
> which removes the line "world" and adds the line "git". So finally,
> README.md will contain only "git".
>
> Regards,
> Pranit Bauva
-- 
Benchao Li
School of Electronics Engineering and Computer Science, Peking University
Tel:+86-15650713730
Email: libenchao@gmail.com; libenchao@pku.edu.cn
Previous: Pranit BauvaNext: Pranit Bauva
Message 5 of 9 in “bug report”
  1. 李本超May 13, 2016
  2. Pranit BauvaMay 13, 2016
  3. 李本超May 13, 2016
  4. Pranit BauvaMay 13, 2016
  5. 李本超May 13, 2016
  6. Pranit BauvaMay 13, 2016
  7. 李本超May 13, 2016
  8. Jeff KingMay 13, 2016
  9. 李本超May 13, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.