1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Git中級者が知っておくべき5つのテクニック

Posted at

今回は私が実際に現場で使用しているGit中級者向けテクニックを紹介します。

1. インタラクティブリベース:コミット履歴の整理

インタラクティブリベースを使用すると、複数のコミットを整理したり統合したりすることができます。

使用例:

git rebase -i HEAD~3

このコマンドを実行すると、直近3つのコミットを操作できるエディタが開きます。ここで各コミットに対して、pick(そのまま使用)、squash(前のコミットと統合)、edit(コミット内容を編集)などの操作を選択できます。

  • 注意点
    • 公開リポジトリの履歴を変更する場合は、チームメンバーに事前に通知することが推奨されます。
    • リベース操作はコンフリクトを引き起こす可能性があるため、慎重に行う必要があります。

2. スタッシュの使用:作業コンテキストの迅速な切り替え

git stashコマンドを使用すると、作業中の変更を一時的に保存し、別の作業に切り替えることができます。

特定ファイルのみをスタッシュする:

git stash push -m "機能A の作業中" path/to/file1 path/to/file2

スタッシュの適用:

git stash pop

活用シーン:

  • 日常的なGit操作の効率化
  • 長いコマンドの簡略化

3. Git aliasの設定:コマンド入力の効率化

頻繁に使用するGitコマンドにエイリアスを設定することで、入力の手間を削減できます。

.gitconfigファイルの設定例:

[alias]
    st = status
    co = checkout
    br = branch
    ci = commit
    unstage = reset HEAD --
    last = log -1 HEAD
    visual = !gitk

活用シーン:

  • 日常的なGit操作の効率化
  • 長いコマンドの簡略化
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?