Posts

Showing posts from 2022

How can I remove a specific item from an array? (Javascript)

  Find the   index   of the array element you want to remove using   indexOf , and then remove that index with   splice . The splice() method changes the contents of an array by removing existing elements and/or adding new elements. const array = [ 2 , 5 , 9 ]; console . log (array); const index = array. indexOf ( 5 ); if (index > - 1 ) { array. splice (index, 1 ); // 2nd parameter means remove one item only } // array = [2, 9] console . log (array);

How do I delete a Git branch locally and remotely?

  Executive Summary $ git push -d <remote_name> <branchname> $ git branch -d <branchname> Note:  In most cases,  <remote_name>  will be  origin . Delete Local Branch To delete the  local  branch use one of the following: $ git branch -d <branch_name> $ git branch -D <branch_name> The  -d  option is an alias for  --delete , which only deletes the branch if it has already been fully merged in its upstream branch. The  -D  option is an alias for  --delete --force , which deletes the branch "irrespective of its merged status." [Source:  man git-branch ] As of  Git v2.3 ,  git branch -d  (delete) learned to honor the  -f  (force) flag. You will receive an error if you try to delete the currently selected branch. Delete Remote Branch As of  Git v1.7.0 , you can delete a  remote  branch using $ git push <remote_name> --delete <branch_name...

How do I undo the most recent local commits in Git?

  $ git commit -m "Something terribly misguided" # (0: Your Accident) $ git reset HEAD~ # (1) [ edit files as necessary ] # (2) $ git add . # (3) $ git commit -c ORIG_HEAD # (4) git reset  is the command responsible for the  undo . It will undo your last commit while  leaving your working tree (the state of your files on disk) untouched.  You'll need to add them again before you can commit them again). Make corrections to  working tree  files. git add  anything that you want to include in your new commit. Commit the changes, reusing the old commit message.  reset  copied the old head to  .git/ORIG_HEAD ;  commit  with  -c ORIG_HEAD  will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the  -C ...