How to get the modified files(before and after) from git version server?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Now here is the commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb, I want to get this commit id code which were modified only.



I use git show 41f9f4e392ab50db264e0328de7d69f1f10646eb to see modified files, how can I download these both after modified and before modified version via Linux git command? In a word, I just want to compare the differences from before and after commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb to merge code easily.



Any idea will be helpful, thanks in advance.







share|improve this question






















  • If you want to compare what's different, git show already shows the differences. Why do you need the files?
    – muru
    Jan 31 at 4:02










  • stackoverflow.com/questions/610208/…
    – cas
    Jan 31 at 4:10










  • @ muru I need to get the midified files(before & after) then compare them, and merge them to another code branch, so I need the modified(before & after) files.
    – Huang
    Jan 31 at 4:33














up vote
1
down vote

favorite












Now here is the commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb, I want to get this commit id code which were modified only.



I use git show 41f9f4e392ab50db264e0328de7d69f1f10646eb to see modified files, how can I download these both after modified and before modified version via Linux git command? In a word, I just want to compare the differences from before and after commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb to merge code easily.



Any idea will be helpful, thanks in advance.







share|improve this question






















  • If you want to compare what's different, git show already shows the differences. Why do you need the files?
    – muru
    Jan 31 at 4:02










  • stackoverflow.com/questions/610208/…
    – cas
    Jan 31 at 4:10










  • @ muru I need to get the midified files(before & after) then compare them, and merge them to another code branch, so I need the modified(before & after) files.
    – Huang
    Jan 31 at 4:33












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Now here is the commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb, I want to get this commit id code which were modified only.



I use git show 41f9f4e392ab50db264e0328de7d69f1f10646eb to see modified files, how can I download these both after modified and before modified version via Linux git command? In a word, I just want to compare the differences from before and after commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb to merge code easily.



Any idea will be helpful, thanks in advance.







share|improve this question














Now here is the commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb, I want to get this commit id code which were modified only.



I use git show 41f9f4e392ab50db264e0328de7d69f1f10646eb to see modified files, how can I download these both after modified and before modified version via Linux git command? In a word, I just want to compare the differences from before and after commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb to merge code easily.



Any idea will be helpful, thanks in advance.









share|improve this question













share|improve this question




share|improve this question








edited Jan 31 at 4:45









galoget

36319




36319










asked Jan 31 at 3:57









Huang

184




184











  • If you want to compare what's different, git show already shows the differences. Why do you need the files?
    – muru
    Jan 31 at 4:02










  • stackoverflow.com/questions/610208/…
    – cas
    Jan 31 at 4:10










  • @ muru I need to get the midified files(before & after) then compare them, and merge them to another code branch, so I need the modified(before & after) files.
    – Huang
    Jan 31 at 4:33
















  • If you want to compare what's different, git show already shows the differences. Why do you need the files?
    – muru
    Jan 31 at 4:02










  • stackoverflow.com/questions/610208/…
    – cas
    Jan 31 at 4:10










  • @ muru I need to get the midified files(before & after) then compare them, and merge them to another code branch, so I need the modified(before & after) files.
    – Huang
    Jan 31 at 4:33















If you want to compare what's different, git show already shows the differences. Why do you need the files?
– muru
Jan 31 at 4:02




If you want to compare what's different, git show already shows the differences. Why do you need the files?
– muru
Jan 31 at 4:02












stackoverflow.com/questions/610208/…
– cas
Jan 31 at 4:10




stackoverflow.com/questions/610208/…
– cas
Jan 31 at 4:10












@ muru I need to get the midified files(before & after) then compare them, and merge them to another code branch, so I need the modified(before & after) files.
– Huang
Jan 31 at 4:33




@ muru I need to get the midified files(before & after) then compare them, and merge them to another code branch, so I need the modified(before & after) files.
– Huang
Jan 31 at 4:33










2 Answers
2






active

oldest

votes

















up vote
3
down vote













To see the state of files before and after a given commit, check out its parent:



git checkout 41f9f4e3~1


then the commit itself:



git checkout 41f9f4e3


However, it’s hardly ever necessary to look at details of a change in this way. In your case, to apply a commit to another branch, cherry pick it:



git checkout $target_branch
git cherry-pick -x 41f9f4e3


(replacing $target_branch as appropriate). The -x option adds a comment in the commit message with the origin of the cherry-pick.






share|improve this answer



























    up vote
    1
    down vote



    accepted










    Thanks all, I have found the correct way, here it is.



    #!/bin/bash
    from_id=$1
    to_id=$2
    #echo $from_id
    #echo $to_id
    diffpath='patch/diff.log'
    newpath='patch/new/'
    oldpath='patch/old/'
    rm -rf patch
    mkdir -p $newpath
    mkdir -p $oldpath
    git diff $from_id $to_id --raw > $diffpath
    cat $diffpath | while read line
    do
    #echo =====================================
    #echo $line
    OLD_IFS="$IFS"
    IFS=" "
    arr=($line)
    IFS="$OLD_IFS"
    #echo $arr[4]
    filepath=$arr[4]##*
    #echo $filepath
    newid=$arr[2]%%...
    #echo $newid
    oldid=$arr[3]%%...
    #echo $oldid

    if [ "$newid"x != "0000000"x ]; then
    newfilepath=$newpath$filepath
    echo $newfilepath
    dirpath=$newfilepath%/*
    echo $dirpath
    mkdir -p $dirpath
    git cat-file -p $newid > $newfilepath
    fi

    if [ "$oldid"x != "0000000"x ]; then
    oldfilepath=$oldpath$filepath
    echo $oldfilepath
    dirpath=$oldfilepath%/*
    echo $dirpath
    mkdir -p $dirpath
    git cat-file -p $oldid > $oldfilepath
    fi
    done


    You will found the new directory named patch in current working directory after doing this.






    share|improve this answer






















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420855%2fhow-to-get-the-modified-filesbefore-and-after-from-git-version-server%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote













      To see the state of files before and after a given commit, check out its parent:



      git checkout 41f9f4e3~1


      then the commit itself:



      git checkout 41f9f4e3


      However, it’s hardly ever necessary to look at details of a change in this way. In your case, to apply a commit to another branch, cherry pick it:



      git checkout $target_branch
      git cherry-pick -x 41f9f4e3


      (replacing $target_branch as appropriate). The -x option adds a comment in the commit message with the origin of the cherry-pick.






      share|improve this answer
























        up vote
        3
        down vote













        To see the state of files before and after a given commit, check out its parent:



        git checkout 41f9f4e3~1


        then the commit itself:



        git checkout 41f9f4e3


        However, it’s hardly ever necessary to look at details of a change in this way. In your case, to apply a commit to another branch, cherry pick it:



        git checkout $target_branch
        git cherry-pick -x 41f9f4e3


        (replacing $target_branch as appropriate). The -x option adds a comment in the commit message with the origin of the cherry-pick.






        share|improve this answer






















          up vote
          3
          down vote










          up vote
          3
          down vote









          To see the state of files before and after a given commit, check out its parent:



          git checkout 41f9f4e3~1


          then the commit itself:



          git checkout 41f9f4e3


          However, it’s hardly ever necessary to look at details of a change in this way. In your case, to apply a commit to another branch, cherry pick it:



          git checkout $target_branch
          git cherry-pick -x 41f9f4e3


          (replacing $target_branch as appropriate). The -x option adds a comment in the commit message with the origin of the cherry-pick.






          share|improve this answer












          To see the state of files before and after a given commit, check out its parent:



          git checkout 41f9f4e3~1


          then the commit itself:



          git checkout 41f9f4e3


          However, it’s hardly ever necessary to look at details of a change in this way. In your case, to apply a commit to another branch, cherry pick it:



          git checkout $target_branch
          git cherry-pick -x 41f9f4e3


          (replacing $target_branch as appropriate). The -x option adds a comment in the commit message with the origin of the cherry-pick.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 31 at 5:18









          Stephen Kitt

          142k22308370




          142k22308370






















              up vote
              1
              down vote



              accepted










              Thanks all, I have found the correct way, here it is.



              #!/bin/bash
              from_id=$1
              to_id=$2
              #echo $from_id
              #echo $to_id
              diffpath='patch/diff.log'
              newpath='patch/new/'
              oldpath='patch/old/'
              rm -rf patch
              mkdir -p $newpath
              mkdir -p $oldpath
              git diff $from_id $to_id --raw > $diffpath
              cat $diffpath | while read line
              do
              #echo =====================================
              #echo $line
              OLD_IFS="$IFS"
              IFS=" "
              arr=($line)
              IFS="$OLD_IFS"
              #echo $arr[4]
              filepath=$arr[4]##*
              #echo $filepath
              newid=$arr[2]%%...
              #echo $newid
              oldid=$arr[3]%%...
              #echo $oldid

              if [ "$newid"x != "0000000"x ]; then
              newfilepath=$newpath$filepath
              echo $newfilepath
              dirpath=$newfilepath%/*
              echo $dirpath
              mkdir -p $dirpath
              git cat-file -p $newid > $newfilepath
              fi

              if [ "$oldid"x != "0000000"x ]; then
              oldfilepath=$oldpath$filepath
              echo $oldfilepath
              dirpath=$oldfilepath%/*
              echo $dirpath
              mkdir -p $dirpath
              git cat-file -p $oldid > $oldfilepath
              fi
              done


              You will found the new directory named patch in current working directory after doing this.






              share|improve this answer


























                up vote
                1
                down vote



                accepted










                Thanks all, I have found the correct way, here it is.



                #!/bin/bash
                from_id=$1
                to_id=$2
                #echo $from_id
                #echo $to_id
                diffpath='patch/diff.log'
                newpath='patch/new/'
                oldpath='patch/old/'
                rm -rf patch
                mkdir -p $newpath
                mkdir -p $oldpath
                git diff $from_id $to_id --raw > $diffpath
                cat $diffpath | while read line
                do
                #echo =====================================
                #echo $line
                OLD_IFS="$IFS"
                IFS=" "
                arr=($line)
                IFS="$OLD_IFS"
                #echo $arr[4]
                filepath=$arr[4]##*
                #echo $filepath
                newid=$arr[2]%%...
                #echo $newid
                oldid=$arr[3]%%...
                #echo $oldid

                if [ "$newid"x != "0000000"x ]; then
                newfilepath=$newpath$filepath
                echo $newfilepath
                dirpath=$newfilepath%/*
                echo $dirpath
                mkdir -p $dirpath
                git cat-file -p $newid > $newfilepath
                fi

                if [ "$oldid"x != "0000000"x ]; then
                oldfilepath=$oldpath$filepath
                echo $oldfilepath
                dirpath=$oldfilepath%/*
                echo $dirpath
                mkdir -p $dirpath
                git cat-file -p $oldid > $oldfilepath
                fi
                done


                You will found the new directory named patch in current working directory after doing this.






                share|improve this answer
























                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  Thanks all, I have found the correct way, here it is.



                  #!/bin/bash
                  from_id=$1
                  to_id=$2
                  #echo $from_id
                  #echo $to_id
                  diffpath='patch/diff.log'
                  newpath='patch/new/'
                  oldpath='patch/old/'
                  rm -rf patch
                  mkdir -p $newpath
                  mkdir -p $oldpath
                  git diff $from_id $to_id --raw > $diffpath
                  cat $diffpath | while read line
                  do
                  #echo =====================================
                  #echo $line
                  OLD_IFS="$IFS"
                  IFS=" "
                  arr=($line)
                  IFS="$OLD_IFS"
                  #echo $arr[4]
                  filepath=$arr[4]##*
                  #echo $filepath
                  newid=$arr[2]%%...
                  #echo $newid
                  oldid=$arr[3]%%...
                  #echo $oldid

                  if [ "$newid"x != "0000000"x ]; then
                  newfilepath=$newpath$filepath
                  echo $newfilepath
                  dirpath=$newfilepath%/*
                  echo $dirpath
                  mkdir -p $dirpath
                  git cat-file -p $newid > $newfilepath
                  fi

                  if [ "$oldid"x != "0000000"x ]; then
                  oldfilepath=$oldpath$filepath
                  echo $oldfilepath
                  dirpath=$oldfilepath%/*
                  echo $dirpath
                  mkdir -p $dirpath
                  git cat-file -p $oldid > $oldfilepath
                  fi
                  done


                  You will found the new directory named patch in current working directory after doing this.






                  share|improve this answer














                  Thanks all, I have found the correct way, here it is.



                  #!/bin/bash
                  from_id=$1
                  to_id=$2
                  #echo $from_id
                  #echo $to_id
                  diffpath='patch/diff.log'
                  newpath='patch/new/'
                  oldpath='patch/old/'
                  rm -rf patch
                  mkdir -p $newpath
                  mkdir -p $oldpath
                  git diff $from_id $to_id --raw > $diffpath
                  cat $diffpath | while read line
                  do
                  #echo =====================================
                  #echo $line
                  OLD_IFS="$IFS"
                  IFS=" "
                  arr=($line)
                  IFS="$OLD_IFS"
                  #echo $arr[4]
                  filepath=$arr[4]##*
                  #echo $filepath
                  newid=$arr[2]%%...
                  #echo $newid
                  oldid=$arr[3]%%...
                  #echo $oldid

                  if [ "$newid"x != "0000000"x ]; then
                  newfilepath=$newpath$filepath
                  echo $newfilepath
                  dirpath=$newfilepath%/*
                  echo $dirpath
                  mkdir -p $dirpath
                  git cat-file -p $newid > $newfilepath
                  fi

                  if [ "$oldid"x != "0000000"x ]; then
                  oldfilepath=$oldpath$filepath
                  echo $oldfilepath
                  dirpath=$oldfilepath%/*
                  echo $dirpath
                  mkdir -p $dirpath
                  git cat-file -p $oldid > $oldfilepath
                  fi
                  done


                  You will found the new directory named patch in current working directory after doing this.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 3 at 12:29









                  cas

                  37.7k44393




                  37.7k44393










                  answered Feb 2 at 7:05









                  Huang

                  184




                  184






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420855%2fhow-to-get-the-modified-filesbefore-and-after-from-git-version-server%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay