surendar's Profile

1714
Points

Questions
35

Answers
107

  • To a specific commit, git creates a detached branch.

    $ git branch
    
    

    few things see like ,

    * (detached from 3i4j25)
    
    master
    
    other_branch
    
    

    In the master branch  head you need to checkout to your master branch again:

    $ git checkout master
    
    

    In the detached branch command will automatically delete.

    git checkout doesn’t work, to lose code git  requires you to deal with these files.

    Stash your modifications

    $ git stash
    
    

    Discard the changes reset-ing the detached branch:

    $ git reset --hard
    
    

    Create a new branch with the previous modifications and commit them:

    $ git checkout -b my_new_branch
    
    $ git add my_file.ext
    
    $ git commit -m "My cool msg"
    
    
    $ git checkout master
    
    
    • 635 views
    • 3 answers
    • 0 votes
  • To discard the changes,

    git checkout -- <file>
    git checkout branch
    

    To keep the changes,

    git stash save
    git checkout branch
    git stash pop
    
    • 574 views
    • 4 answers
    • 0 votes
  • Git is probably before tracking the file.

    From the gitignore docs:  

    By using git rm –cached. you can stop tracking a file in currently tracked.

    Replacing  the project and username :

    git rm --cached [project].xcodeproj/project.xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate
    git commit -m "Removed file that shouldn't be tracked"
    

    Rather use the –a option to git commit that will add all files to modified or deleted.

    • 1185 views
    • 4 answers
    • 0 votes
  • Asked on January 10, 2019 in Git.

    Try this alternative code for  short Git version hash:

    git log -1 --abbrev-commit
    
    

    Or,

    git log --abbrev-commit
    
    

    Tabulation  the log entries with shorten SHA-1 checksum.

    • 552 views
    • 4 answers
    • 0 votes
  • Top of Google is”working on the wrong branch” to checkout the branch to be working on. No need to hoard anything:

    git checkout branch123
    
    

    Checkout the modified file  to stop  overwrite  the working directory,

    Update : This method will  work when the files is modified in the working directory for both master and branch123.

     

    • 534 views
    • 4 answers
    • 0 votes
  • Try this  below solution:

    When the terminal  is similar to predicament keep in mind  to try and type ‘quit’, ‘exit’ as well as stop the key connection with’Ctrl + C’.

    • 530 views
    • 4 answers
    • 0 votes
  • Asked on January 9, 2019 in Git.

    It is basically to switch your SSH identity when running the git commands.

    To the host alias approach in the below answer:

    • Work with any git commands or aliases, even if you can’t specify the remote explicitly.
    • Easier to work with many repositories because you only need to set it up once per client machine, not once per repository on each client machine.

     

    Small scripts and a git alias admin

    git admin push
    

    . You could even do git admin clone … to clone a repository that can access to using your “admin” key.

    Procedure  1: Create the alternative SSH keys, optionally set a passphrase in case you’re doing this on someone else’s machine.

    Procedure   2: Create a script called “ssh-as.sh” that runs stuff that uses SSH, but uses a given SSH key rather than the default:

    #!/bin/bash
    exec ssh ${SSH_KEYFILE+-i "$SSH_KEYFILE"} "[email protected]"
    

    Procedure    3: Create a script called “git-as.sh” that runs git commands using the given SSH key.

    #!/bin/bash
    SSH_KEYFILE=$1 GIT_SSH=${BASH_SOURCE%/*}/ssh-as.sh exec git "${@:2}"
    

    Procedure    4: Add an alias using something appropriate for “PATH_TO_SCRIPTS_DIR” below:

    # Run git commands as the SSH identity provided by the keyfile ~/.ssh/admin
    git config --global alias.admin \!"PATH_TO_SCRIPTS_DIR/git-as.sh ~/.ssh/admin"
    

     

    • 489 views
    • 4 answers
    • 0 votes
  • Asked on January 8, 2019 in Git.

    Abort a git cherry-pick  is alternative below code:

    git reset --hard HEAD
    
    • 459 views
    • 3 answers
    • 0 votes
  • You can’t ignore that directory/subdirectory to remove all files from the target directory from the repo and then ignore that folder.

    • 474 views
    • 3 answers
    • 0 votes
  • You can easily checkout the individual files you missed/removed :

    git checkout HEAD path/to/file path/to/another_file
    
    

    Single changes intact with no computing.

    • 531 views
    • 3 answers
    • 0 votes