Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Git Diff and add commit in one shot

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 333
    Comment on it
    Previous Git Blogs

    1. Intialize git repostiory
    2. First Commit
    3. Two tree architecture and Three tree architecture
    4. Best basic practices for writing commit messages
    5. Viewing the commit logs
    6. Git Basic WorkFlow
    7. What is HEAD pointer in GIT
    8. Git Configuration
    9. Viewing history
    10. Updating a file and adding it to repository
    11. Viewing history
    12. Git Config, Add, Commit, View, Diff summary
    13. Pictorial Representation of basic Git flow

    I edited readme.txt file and added a new line in it `this is really cool feature`, and run a git command

    naveen@naveen:/var/www/html/RND/symfony_sites/symfony_todoapp$ git diff readme.txt
    Git Display
    diff --git a/readme.txt b/readme.txt
    index 3ebcb13..194e746 100644
    --- a/readme.txt
    +++ b/readme.txt
    @@ -1,3 +1,5 @@
     Please Read me
     MY new changes
     adding multiple commits to stagging
    +this is really cool feature

    The + indicates the the new line added at line @@ -1,3 +1,5 @@, these line numberzs are useful as we can go to the text editor and track them down with these lines. no lets again edit the readme.txt file and edit in what we wrote wew previous lets say I change the text to `this is really cool and appreciative feature`
    Sometime what git does it shows you two line one in minus and the second in + , Actually this the only one line where we have make the changes. its tries to show you how was the line before and how it is now . It ok and helpful to too, but why it show me whole can't it only show me only the words i have changed yes we can do it with.

    naveen@naveen:/var/www/html/RND/symfony_sites/symfony_todoapp$ git --diff --color-words readme.txt

    Now notice that it comes up, and it gives me that same information, but instead of having two separate lines it gave me a different format, and it put the change here side by side.

    add and commit in one shot

    we can do this with git commit with the -a option, that's telling it to add it to the staging index and then commit it. All in one shot.So it's going to add it and commit it and allow us to skip that process of actually having to say add them one by one.

    -am is used to add with message

    naveen@naveen:/var/www/html/RND/symfony_sites/symfony_todoapp$ git commit -am "Replace the text of readme.txt file"

    Remember this speed up the work but it do have some disadvantages and you need to be careful about them.

    1. The first is that, of course, this grabs everything that is in your working directory. So if there were some things that you didn't want to include in the change,they're going to get pushed up there as well.
    2. Files that are not tracked, or files that are being deleted, do not get included in this.
    3. It works well for modifications, but for new files and deleted files it doesn't work well.

    In my case, I am only making modifications and I know that as soon as I finish doing the add of everything, I am going to commit it all.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: