March 14, 2022

Change default directory of Windows command prompt and Windows PowerShell

 Hi all,

Today I will explain the steps to change the default directory for Windows command prompt and Windows PowerShell.

The default directory for both the command prompt and PowerShell is the "system32" folder of the OS installed directory (By default: "C:\windows\system32").

Day in - Day out, we will open the terminals (command prompt / PowerShell) and navigate the source directory. It sometimes irritates and wastes lots of time.

I have come across this situation and want to avoid re-entry the change directory command.

Environment,

I use the command prompt and PowerShell, which are pinned to the taskbar of Windows.


Change default directory of Windows Command Prompt

  1. Right-click on the taskbar pinned Command Prompt icon
  2. Right-click on the "Command Prompt" menu
  3. Select the "Properties" item
  4. Under the "Shortcut" tab, you will find the "Start in:" label
  5. In the respective text box, enter the path you want to navigate by default.
  6. For example, "C:\Projects".

Change default directory of Windows PowerShell

  1. Open the PowerShell with administrator privileges
  2. Create a profile by using the following steps
    1. New-item -type file -force $Profile
  3. This will create a file "Microsoft.PowerShell_profile.ps1" in the current user documents PowerShell folder.
    1. Syntax
        • C:\Users\<UserName>\Documents\WindowsPowerShell
      1. Example
          • C:\Users\PSR\Documents\WindowsPowerShell
      2. Edit file
          • notepad.exe $Profile
        1. Change the default directory
          1. Syntax
              • Set-Location <Directory Path>
            1. Example
                • Set-Location C:\Projects
                  • Clear-Host # To clear the PowerShell screen
              1. Save and close the file
              2. In the PowerShell window, enter the following command to change the profile
                  • . $Profile
                1. It immediately changes from the current directory to the updated default directory.
                2. Close the PowerShell and try to open the PowerShell again to see the change in the directory.
                Hope the above information is helpful to you reduce the change directories in day-to-day life.

                Send me your valuable feedback to psrdotcom@gmail.com.

                March 10, 2022

                Git remove a specific commit(s) from history

                 Hi all,

                This blog post will let you know about the process of removing the git commit from git history.


                Sample Git log

                > git log 

                38384b3 initial commit

                f96751b UI changes

                2154131 file added

                bf9b9c1 Logic corrections

                3e75ab7 Bug fix -> (HEAD)


                Use case

                Remove the commit "file added"


                Procedure

                • Rebase in interaction mode one commit above which we want to remove.

                > git rebase -i f96751b

                • All the commits up to the specified commit will be listed in an order with the prefix "pick". Along with commit messages, the useful commands are available like below.

                pick = use commit

                reword = use commit, but edit the commit message

                edit = use commit, but stop for amending

                squash = use commit, but meld into previous commit

                fixup = like "squash", but discard this commit's log message

                exec = run command (the rest of the line) using shell

                drop = remove commit

                • Delete the unwanted commits from the file
                  • Press 'd' twice to delete line (in case of vi editor)
                • Save and quit the editor
                  • esc -> :wq (in case of vi editor)
                • If there are any merge conflicts, resolve it and perform rebase continue
                  • > git rebase --continue
                • Once all the merges are completed, perform the push operation
                  • > git push --force-with-lease origin
                Hope this helps you make sure, you have clean git history.

                Feel free to send your suggestions and comments to psrdotcom@gmail.com


                Featured Post

                Java Introdcution

                Please send your review and feedback to psrdotcom@gmail.com